Files
FreshRSS/app/Models/SimplePieResponse.php
Inverle 7d4854a0a4 Create separate Retry-After files for proxies (#8029)
* Create separate `Retry-After` files for proxies
Bad proxies are able to send a false `Retry-After` header and affect the availability of feeds (domain-wide) for other users.
This PR starts including the address of the proxy if present in filenames for `Retry-After` to mitigate the issue.

* Reduce code changes

* Sync SimplePie fork
https://github.com/FreshRSS/simplepie/pull/62

---------

Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
2025-11-04 12:48:31 +01:00

33 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
final class FreshRSS_SimplePieResponse extends \SimplePie\File
{
#[\Override]
protected function on_http_response($response, array $curl_options = []): void {
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);
}
}
}
}
}