aboutsummaryrefslogtreecommitdiff
path: root/lib/lib_rss.php
diff options
context:
space:
mode:
authorGravatar Alexandre Alapetite <alexandre@alapetite.fr> 2025-10-01 23:07:38 +0200
committerGravatar GitHub <noreply@github.com> 2025-10-01 23:07:38 +0200
commit49c96fe3ec2273309d99cd2a6d4d80332e09557b (patch)
treedf94c0235ef9ccd2ee222d832a9e8f27d70434c4 /lib/lib_rss.php
parent8e57e28a9a1b37987d6ce9c6406df00a401bcf72 (diff)
Fix SimplePie support of HTTP trailer headers (#7983)
* Fix SimplePie support of HTTP trailer headers fix https://github.com/FreshRSS/FreshRSS/discussions/7981 https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Trailer https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Server-Timing We need to use content-length to know where the body stops, but content-length is wrong is any compression was used. So let cURL perform the separation of HTTP headers and body instead of using the SimplePie parser. * Minor whitespace * Same change for lib_rss * Move changes to SimplePie repo https://github.com/FreshRSS/simplepie/pull/55 https://github.com/FreshRSS/simplepie/pull/57
Diffstat (limited to 'lib/lib_rss.php')
-rw-r--r--lib/lib_rss.php19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/lib_rss.php b/lib/lib_rss.php
index 7bcb3b58a..6779a4560 100644
--- a/lib/lib_rss.php
+++ b/lib/lib_rss.php
@@ -633,13 +633,20 @@ function httpGet(string $url, string $cachePath, string $type = 'html', array $a
CURLOPT_CONNECTTIMEOUT => $feed_timeout > 0 ? $feed_timeout : $limits['timeout'],
CURLOPT_TIMEOUT => $feed_timeout > 0 ? $feed_timeout : $limits['timeout'],
CURLOPT_MAXREDIRS => 4,
- CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_ENCODING => '', //Enable all encodings
//CURLOPT_VERBOSE => 1, // To debug sent HTTP headers
]);
+ $responseHeaders = '';
+ curl_setopt($ch, CURLOPT_HEADERFUNCTION, function (\CurlHandle $ch, string $header) use (&$responseHeaders) {
+ if (trim($header) !== '') { // Skip e.g. separation with trailer headers
+ $responseHeaders .= $header;
+ }
+ return strlen($header);
+ });
+
curl_setopt_array($ch, FreshRSS_Context::systemConf()->curl_options);
if (is_array($attributes['curl_params'] ?? null)) {
@@ -666,22 +673,20 @@ function httpGet(string $url, string $cachePath, string $type = 'html', array $a
curl_setopt_array($ch, $curl_options);
- $response = curl_exec($ch);
+ $body = curl_exec($ch);
$c_status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$c_content_type = '' . curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
$c_effective_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$c_redirect_count = curl_getinfo($ch, CURLINFO_REDIRECT_COUNT);
$c_error = curl_error($ch);
- $body = false;
$headers = [];
- if ($response !== false) {
+ if ($body !== false) {
assert($c_redirect_count >= 0);
- $response = \SimplePie\HTTP\Parser::prepareHeaders(is_string($response) ? $response : '', $c_redirect_count + 1);
- $parser = new \SimplePie\HTTP\Parser($response);
+ $responseHeaders = \SimplePie\HTTP\Parser::prepareHeaders($responseHeaders, $c_redirect_count + 1);
+ $parser = new \SimplePie\HTTP\Parser($responseHeaders);
if ($parser->parse()) {
$headers = $parser->headers;
- $body = $parser->body;
}
}