Browse Source

Fix curl response parsing (#7866)

* Fix curl response parsing

* Specify redirect count with `\SimplePie\HTTP\Parser::prepareHeaders()` instead

Simply notify SimplePie of the redirect count before parsing

* Better error check

* Simplify
Inverle 7 months ago
parent
commit
43248b461d
1 changed files with 10 additions and 7 deletions
  1. 10 7
      lib/lib_rss.php

+ 10 - 7
lib/lib_rss.php

@@ -643,13 +643,16 @@ function httpGet(string $url, string $cachePath, string $type = 'html', array $a
 	$c_redirect_count = curl_getinfo($ch, CURLINFO_REDIRECT_COUNT);
 	$c_error = curl_error($ch);
 
-	$parser = new \SimplePie\HTTP\Parser(is_string($response) ? $response : '');
-	if ($parser->parse()) {
-		$headers = $parser->headers;
-		$body = $parser->body;
-	} else {
-		$headers = [];
-		$body = false;
+	$body = false;
+	$headers = [];
+	if ($response !== 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);
+		if ($parser->parse()) {
+			$headers = $parser->headers;
+			$body = $parser->body;
+		}
 	}
 
 	$fail = $c_status != 200 || $c_error != '' || $body === false;