diff options
| author | 2025-08-30 16:28:37 +0200 | |
|---|---|---|
| committer | 2025-08-30 16:28:37 +0200 | |
| commit | 2b02ca59c6af1cfe087ec7e6ea9773cffd48fd50 (patch) | |
| tree | 7862c80a7691b9fdafbd7a97263a89d84492fb19 /app/Utils/httpUtil.php | |
| parent | 379a387ddeabdab428c2c6257ff6521f69e5d974 (diff) | |
Include port number for HTTP Retry-After (#7875)
fix https://github.com/FreshRSS/FreshRSS/issues/7870 (partially)
Diffstat (limited to 'app/Utils/httpUtil.php')
| -rw-r--r-- | app/Utils/httpUtil.php | 28 |
1 files changed, 20 insertions, 8 deletions
diff --git a/app/Utils/httpUtil.php b/app/Utils/httpUtil.php index 12ebc3d07..2b57b410f 100644 --- a/app/Utils/httpUtil.php +++ b/app/Utils/httpUtil.php @@ -5,6 +5,18 @@ final class FreshRSS_http_Util { private const RETRY_AFTER_PATH = DATA_PATH . '/Retry-After/'; + private static function getRetryAfterFile(string $url): string { + $domain = parse_url($url, PHP_URL_HOST); + if (!is_string($domain) || $domain === '') { + return ''; + } + $port = parse_url($url, PHP_URL_PORT); + if (is_int($port)) { + $domain .= ':' . $port; + } + return self::RETRY_AFTER_PATH . urlencode($domain) . '.txt'; + } + /** * Clean up old Retry-After files */ @@ -31,16 +43,16 @@ final class FreshRSS_http_Util { if (rand(0, 30) === 1) { // Remove old files once in a while self::cleanRetryAfters(); } - $domain = parse_url($url, PHP_URL_HOST); - if (!is_string($domain) || $domain === '') { + $txt = self::getRetryAfterFile($url); + if ($txt === '') { return 0; } - $retryAfter = @filemtime(self::RETRY_AFTER_PATH . $domain . '.txt') ?: 0; + $retryAfter = @filemtime($txt) ?: 0; if ($retryAfter <= 0) { return 0; } if ($retryAfter < time()) { - @unlink(self::RETRY_AFTER_PATH . $domain . '.txt'); + @unlink($txt); return 0; } return $retryAfter; @@ -50,8 +62,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 { - $domain = parse_url($url, PHP_URL_HOST); - if (!is_string($domain) || $domain === '') { + $txt = self::getRetryAfterFile($url); + if ($txt === '') { return 0; } @@ -65,8 +77,8 @@ final class FreshRSS_http_Util { $retryAfter = min($retryAfter, time() + max(3600, $limits['retry_after_max'] ?? 0)); @mkdir(self::RETRY_AFTER_PATH); - if (!touch(self::RETRY_AFTER_PATH . $domain . '.txt', $retryAfter)) { - Minz_Log::error('Failed to set Retry-After for ' . $domain); + if (!touch($txt, $retryAfter)) { + Minz_Log::error('Failed to set Retry-After for ' . $url); return 0; } return $retryAfter; |
