Merge pull request 'Handle no response body, file_get_contents() failure in UrlHelper::fetch()' (#78) from wn/tt-rss:feature/handle-no-response-body into master

Reviewed-on: https://dev.tt-rss.org/fox/tt-rss/pulls/78
This commit is contained in:
fox 2022-08-15 07:27:23 +03:00
commit 3b7174788d
1 changed files with 15 additions and 1 deletions

View File

@ -462,7 +462,11 @@ class UrlHelper {
} }
if (!$contents) { if (!$contents) {
if (curl_errno($ch) === 0) {
self::$fetch_last_error = 'Successful response, but no content was received.';
} else {
self::$fetch_last_error = curl_errno($ch) . " " . curl_error($ch); self::$fetch_last_error = curl_errno($ch) . " " . curl_error($ch);
}
curl_close($ch); curl_close($ch);
return false; return false;
} }
@ -543,6 +547,11 @@ class UrlHelper {
$data = @file_get_contents($url, false, $context); $data = @file_get_contents($url, false, $context);
if ($data === false) {
self::$fetch_last_error = "'file_get_contents' failed.";
return false;
}
foreach ($http_response_header as $header) { foreach ($http_response_header as $header) {
if (strstr($header, ": ") !== false) { if (strstr($header, ": ") !== false) {
list ($key, $value) = explode(": ", $header); list ($key, $value) = explode(": ", $header);
@ -578,6 +587,11 @@ class UrlHelper {
return false; return false;
} }
if (!$data) {
self::$fetch_last_error = 'Successful response, but no content was received.';
return false;
}
$is_gzipped = RSSUtils::is_gzipped($data); $is_gzipped = RSSUtils::is_gzipped($data);
if ($is_gzipped && $data) { if ($is_gzipped && $data) {