mirror of
https://github.com/FreshRSS/FreshRSS.git
synced 2026-10-28 14:08:45 -04:00
* Fix domain-wide Retry-After - Fix the domain-wide HTTP `Retry-After` for public servers, which has not applied since #8195 (FreshRSS 1.28.0). - `getRetryAfterFile()` passed the bare host name to `Minz_Request::serverIsPublic()`. That function expects a URL, so it always returned `false`. - So a 429 or 503 paused only the URL that got it, despite the log saying "For that domain, will first retry after …", and FreshRSS went on requesting the other feeds of that server. With several Reddit feeds, for instance, each one got its own 429 in turn. - `serverIsPublic()` now gets the URL. Its answer is kept per host for the rest of the request, because it resolves the host name (`dns_get_record()`), and a refresh may load many feeds of the same host. - Fix the per-URL `Retry-After` of servers on a local network (#8195), which never applied to feeds whose URL, as stored, differs from the URL as requested. - Stored URLs are HTML-encoded, e.g. `&` in an RSS-Bridge URL, and may end with `#force_feed`. - `FreshRSS_Feed::load()` checked the stored URL, while the pause is stored for the URL as requested. It now checks the requested URL, as `loadJson()` and `loadHtmlXpath()` already do. * Minor final --------- Co-authored-by: Alexandre Alapetite <alexandre@alapetite.fr>
33 lines
1.2 KiB
PHP
33 lines
1.2 KiB
PHP
<?php
|
|
declare(strict_types=1);
|
|
|
|
use PHPUnit\Framework\Attributes\DataProvider;
|
|
|
|
final class FeedTest extends \PHPUnit\Framework\TestCase {
|
|
|
|
#[DataProvider('provideStoredAndRequestedUrls')]
|
|
public function test_load_obeysRetryAfter(string $storedUrl, string $requestedUrl): void {
|
|
$getRetryAfterFile = new ReflectionMethod(FreshRSS_http_Util::class, 'getRetryAfterFile');
|
|
$file = $getRetryAfterFile->invoke(null, $requestedUrl, '');
|
|
self::assertIsString($file);
|
|
self::assertTrue(touch($file, time() + 600));
|
|
try {
|
|
(new FreshRSS_Feed($storedUrl, validate: false))->load();
|
|
self::fail('The feed was loaded during its Retry-After');
|
|
} catch (FreshRSS_Feed_Exception $e) {
|
|
self::assertStringContainsString('will first retry after', $e->getMessage());
|
|
} finally {
|
|
unlink($file);
|
|
}
|
|
}
|
|
|
|
/** @return array<string,array{string,string}> */
|
|
public static function provideStoredAndRequestedUrls(): array {
|
|
// On a local network, where Retry-After is per URL
|
|
return [
|
|
'HTML-encoded' => ['http://192.168.1.2/?action=display&bridge=Example', 'http://192.168.1.2/?action=display&bridge=Example'],
|
|
'force_feed' => ['http://192.168.1.2/feed#force_feed', 'http://192.168.1.2/feed'],
|
|
];
|
|
}
|
|
}
|