From 76f5bee76d4640169d9a506b5b107f787797879c Mon Sep 17 00:00:00 2001 From: Alexandre Alapetite Date: Thu, 27 Nov 2025 23:31:03 +0100 Subject: Better merging of custom HTTP headers (#8251) Alternative to https://github.com/FreshRSS/FreshRSS/pull/8246 See https://github.com/FreshRSS/FreshRSS/issues/8189#issuecomment-3569434305 --- app/Models/SimplePieFetch.php | 59 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 app/Models/SimplePieFetch.php (limited to 'app/Models/SimplePieFetch.php') diff --git a/app/Models/SimplePieFetch.php b/app/Models/SimplePieFetch.php new file mode 100644 index 000000000..3d5c98b46 --- /dev/null +++ b/app/Models/SimplePieFetch.php @@ -0,0 +1,59 @@ += 2) { + $existingKeys[strtolower(trim($parts[0]))] = true; + } + } + foreach ($headers as $key => $value) { + if (isset($existingKeys[strtolower($key)])) { + unset($headers[$key]); + } + } + } + + parent::__construct($url, $timeout, $redirects, $headers, $useragent, $force_fsockopen, $curl_options); + } + + #[\Override] + protected function on_http_response($response, array $curl_options = []): void { + if (FreshRSS_Context::systemConf()->simplepie_syslog_enabled) { + syslog(LOG_INFO, 'FreshRSS SimplePie GET ' . $this->get_status_code() . ' ' . \SimplePie\Misc::url_remove_credentials($this->get_final_requested_uri())); + } + + if (in_array($this->get_status_code(), [429, 503], true)) { + $parser = new \SimplePie\HTTP\Parser(is_string($response) ? $response : ''); + if ($parser->parse()) { + $headers = $parser->headers; + } else { + $headers = []; + } + + $proxy = is_string($curl_options[CURLOPT_PROXY] ?? null) ? $curl_options[CURLOPT_PROXY] : ''; + $retryAfter = FreshRSS_http_Util::setRetryAfter($this->get_final_requested_uri(), $proxy, $headers['retry-after'] ?? ''); + if ($retryAfter > 0) { + $domain = parse_url($this->get_final_requested_uri(), PHP_URL_HOST); + if (is_string($domain) && $domain !== '') { + if (is_int($port = parse_url($this->get_final_requested_uri(), PHP_URL_PORT))) { + $domain .= ':' . $port; + } + $errorMessage = 'Will retry after ' . date('c', $retryAfter) . ' for domain `' . $domain . '`'; + Minz_Log::notice($errorMessage); + } + } + } + } +} -- cgit v1.2.3