A free, self-hostable news aggregator…
Make httpGet() cache nullable (#8705)
Alexandre Alapetitec4c5c72127a3
diff --git a/app/Utils/httpUtil.php b/app/Utils/httpUtil.phpindex 4b9e77d24..47812ecf7 100644--- a/app/Utils/httpUtil.php+++ b/app/Utils/httpUtil.php@@ -258,6 +258,7 @@ final class FreshRSS_http_Util {/*** @param non-empty-string $url+ * @param string|null $cachePath path to cache file, or `null` to disable caching* @param string $type {html,ico,json,opml,xml}* @param array<string,mixed> $attributes* @param array<int,mixed> $curl_options@@ -267,16 +268,18 @@ final class FreshRSS_http_Util {* * `-429` blocked by active `Retry-After` period;* * `-500` `curl_init()` failure.*/- public static function httpGet(string $url, string $cachePath, string $type = 'html', array $attributes = [], array $curl_options = []): array {+ public static function httpGet(string $url, ?string $cachePath = null, string $type = 'html', array $attributes = [], array $curl_options = []): array {$limits = FreshRSS_Context::systemConf()->limits;$feed_timeout = empty($attributes['timeout']) || !is_numeric($attributes['timeout']) ? 0 : intval($attributes['timeout']);- $cacheMtime = @filemtime($cachePath);- if ($cacheMtime !== false && $cacheMtime > time() - intval($limits['cache_duration'])) {- $body = @file_get_contents($cachePath);- if ($body != false) {- syslog(LOG_DEBUG, 'FreshRSS uses cache for ' . \SimplePie\Misc::url_remove_credentials($url));- return ['body' => $body, 'effective_url' => $url, 'redirect_count' => 0, 'fail' => false, 'status' => -200, 'error' => ''];+ if ($cachePath !== null) {+ $cacheMtime = @filemtime($cachePath);+ if ($cacheMtime !== false && $cacheMtime > time() - intval($limits['cache_duration'])) {+ $body = @file_get_contents($cachePath);+ if ($body != false) {+ syslog(LOG_DEBUG, 'FreshRSS uses cache for ' . \SimplePie\Misc::url_remove_credentials($url));+ return ['body' => $body, 'effective_url' => $url, 'redirect_count' => 0, 'fail' => false, 'status' => -200, 'error' => ''];+ }}}@@ -420,7 +423,7 @@ final class FreshRSS_http_Util {}}- if (file_put_contents($cachePath, $body) === false) {+ if ($cachePath !== null && file_put_contents($cachePath, $body) === false) {Minz_Log::warning("Error saving cache $cachePath for $url");}