From b2caaaca7353e3de505e3d1464e755b0b4751abd Mon Sep 17 00:00:00 2001 From: Gregor Morrill Date: Thu, 25 Jun 2026 16:00:45 -0700 Subject: [PATCH 1/2] Add Accept-Encoding header to fetch method --- Mf2/Parser.php | 1 + 1 file changed, 1 insertion(+) diff --git a/Mf2/Parser.php b/Mf2/Parser.php index cddb0a2..f148147 100644 --- a/Mf2/Parser.php +++ b/Mf2/Parser.php @@ -69,6 +69,7 @@ function fetch($url, $convertClassic = true, &$curlInfo=null) { curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_MAXREDIRS, 5); + curl_setopt($ch, CURLOPT_ENCODING, ''); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Accept: text/html' )); From 8cc61aa3b17c46c09cd1720c84257f57c3ff31a3 Mon Sep 17 00:00:00 2001 From: Gregor Morrill Date: Tue, 7 Jul 2026 20:26:21 -0700 Subject: [PATCH 2/2] Use appropriate cURL constant based on version --- Mf2/Parser.php | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Mf2/Parser.php b/Mf2/Parser.php index f148147..03969fd 100644 --- a/Mf2/Parser.php +++ b/Mf2/Parser.php @@ -63,13 +63,26 @@ function parse($input, $url = null, $convertClassic = true) { * @return array|null canonical microformats2 array structure on success, null on failure */ function fetch($url, $convertClassic = true, &$curlInfo=null) { + $version = '0'; + if (is_array($curl = curl_version())) { + $version = $curl['version']; + } + $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($ch, CURLOPT_MAXREDIRS, 5); - curl_setopt($ch, CURLOPT_ENCODING, ''); + + if (version_compare($version, '7.21.6', '>=')) { + // see https://curl.se/libcurl/c/CURLOPT_ACCEPT_ENCODING.html + curl_setopt($ch, CURLOPT_ACCEPT_ENCODING, ''); + } elseif (version_compare($version, '7.10.5', '>=')) { + // see https://curl.se/ch/7.10.5.html + curl_setopt($ch, CURLOPT_ENCODING, ''); + } + curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'Accept: text/html' ));