diff options
| author | 2025-11-27 23:31:03 +0100 | |
|---|---|---|
| committer | 2025-11-27 23:31:03 +0100 | |
| commit | 76f5bee76d4640169d9a506b5b107f787797879c (patch) | |
| tree | 60bc247ac1d79a4f4f712675b20dab6ad972597b /app | |
| parent | 5e0093aa00a6b52df88f526a5b6f737eff057e0b (diff) | |
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
Diffstat (limited to 'app')
| -rw-r--r-- | app/Models/SimplePieCustom.php | 2 | ||||
| -rw-r--r-- | app/Models/SimplePieFetch.php (renamed from app/Models/SimplePieResponse.php) | 27 |
2 files changed, 27 insertions, 2 deletions
diff --git a/app/Models/SimplePieCustom.php b/app/Models/SimplePieCustom.php index 372ce6d3d..c3593e4a2 100644 --- a/app/Models/SimplePieCustom.php +++ b/app/Models/SimplePieCustom.php @@ -11,7 +11,7 @@ final class FreshRSS_SimplePieCustom extends \SimplePie\SimplePie public function __construct(array $attributes = [], array $curl_options = []) { parent::__construct(); $limits = FreshRSS_Context::systemConf()->limits; - $this->get_registry()->register(\SimplePie\File::class, FreshRSS_SimplePieResponse::class); + $this->get_registry()->register(\SimplePie\File::class, FreshRSS_SimplePieFetch::class); $this->set_useragent(FRESHRSS_USERAGENT); $this->set_cache_name_function('sha1'); $this->set_cache_location(CACHE_PATH); diff --git a/app/Models/SimplePieResponse.php b/app/Models/SimplePieFetch.php index 42625ccf3..3d5c98b46 100644 --- a/app/Models/SimplePieResponse.php +++ b/app/Models/SimplePieFetch.php @@ -1,8 +1,33 @@ <?php declare(strict_types=1); -final class FreshRSS_SimplePieResponse extends \SimplePie\File +final class FreshRSS_SimplePieFetch extends \SimplePie\File { + public function __construct(string $url, int $timeout = 10, int $redirects = 5, + ?array $headers = null, ?string $useragent = null, bool $force_fsockopen = false, array $curl_options = []) { + + // Remove case-insensitively default HTTP headers passed by $headers if they are overridden by $curl_options[CURLOPT_HTTPHEADER] + if (is_array($curl_options[CURLOPT_HTTPHEADER] ?? null) && is_array($headers)) { + $existingKeys = []; + foreach ($curl_options[CURLOPT_HTTPHEADER] as $headerLine) { + if (!is_string($headerLine)) { + continue; + } + $parts = explode(':', $headerLine, 2); + if (count($parts) >= 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) { |
