aboutsummaryrefslogtreecommitdiff
path: root/app/Utils/httpUtil.php
diff options
context:
space:
mode:
authorGravatar Inverle <inverle@proton.me> 2025-11-04 12:48:31 +0100
committerGravatar GitHub <noreply@github.com> 2025-11-04 12:48:31 +0100
commit7d4854a0a4f5665db599f18c34035786465639f3 (patch)
treeed69305612249a91080d42e3fe39021cab15dda2 /app/Utils/httpUtil.php
parent5535067f64fe4285b414a48ae6d16b85fb26f97f (diff)
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>
Diffstat (limited to 'app/Utils/httpUtil.php')
-rw-r--r--app/Utils/httpUtil.php12
1 files changed, 6 insertions, 6 deletions
diff --git a/app/Utils/httpUtil.php b/app/Utils/httpUtil.php
index 2b57b410f..6e176a0d3 100644
--- a/app/Utils/httpUtil.php
+++ b/app/Utils/httpUtil.php
@@ -5,7 +5,7 @@ final class FreshRSS_http_Util {
private const RETRY_AFTER_PATH = DATA_PATH . '/Retry-After/';
- private static function getRetryAfterFile(string $url): string {
+ private static function getRetryAfterFile(string $url, string $proxy): string {
$domain = parse_url($url, PHP_URL_HOST);
if (!is_string($domain) || $domain === '') {
return '';
@@ -14,7 +14,7 @@ final class FreshRSS_http_Util {
if (is_int($port)) {
$domain .= ':' . $port;
}
- return self::RETRY_AFTER_PATH . urlencode($domain) . '.txt';
+ return self::RETRY_AFTER_PATH . urlencode($domain) . (empty($proxy) ? '' : ('_' . urlencode($proxy))) . '.txt';
}
/**
@@ -39,11 +39,11 @@ final class FreshRSS_http_Util {
* Check whether the URL needs to wait for a Retry-After period.
* @return int The timestamp of when the Retry-After expires, or 0 if not set.
*/
- public static function getRetryAfter(string $url): int {
+ public static function getRetryAfter(string $url, string $proxy): int {
if (rand(0, 30) === 1) { // Remove old files once in a while
self::cleanRetryAfters();
}
- $txt = self::getRetryAfterFile($url);
+ $txt = self::getRetryAfterFile($url, $proxy);
if ($txt === '') {
return 0;
}
@@ -61,8 +61,8 @@ final class FreshRSS_http_Util {
/**
* Store the HTTP Retry-After header value of an HTTP `429 Too Many Requests` or `503 Service Unavailable` response.
*/
- public static function setRetryAfter(string $url, string $retryAfter): int {
- $txt = self::getRetryAfterFile($url);
+ public static function setRetryAfter(string $url, string $proxy, string $retryAfter): int {
+ $txt = self::getRetryAfterFile($url, $proxy);
if ($txt === '') {
return 0;
}