diff options
| author | 2020-09-17 10:35:56 +0200 | |
|---|---|---|
| committer | 2020-09-17 10:35:56 +0200 | |
| commit | 1c0e7b4febf597ca92a74c7b3a4fb84e91493f48 (patch) | |
| tree | 8607d1c829d9bdfe18716940644e44f50b72195f | |
| parent | bb9b166eb1be73226d2cf978a05a70ed83faec1e (diff) | |
SimplePie: Fix HTTP 301 permanent redirection (#3180)
* SimplePie: Fix HTTP 301 permanent redirection
When adding feeds it worked fine, but detecting permanent redirects for
existing feeds was sometimes broken (only when PHP open_basedir was not
set).
Indeed, using the built-in CURLOPT_FOLLOWLOCATION instead of the manual
method in SimplePie hides the list of HTTP redirects along the way, and
prevents the distinction of e.g. 301 vs. 302 redirects.
This patch disables CURLOPT_FOLLOWLOCATION in SimplePie, and fixes the
manual method at the same time.
The use of CURLOPT_FOLLOWLOCATION was nevertheless not systematic (only
when open_basedir was not set), so now there is only one logic
independent of open_basedir.
I will send a PR upstream to SimplePie.
How to test: pick a feed with 301 redirection such as HTTP to HTTPS,
e.g. http://ing.dk/rss/term/341
Manually change back to previous address (to simulate a feed that is
changing address)
Refresh feed and observe whether the 301 redirect is obeyed.
* Wrong blank
| -rw-r--r-- | lib/SimplePie/SimplePie/File.php | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/SimplePie/SimplePie/File.php b/lib/SimplePie/SimplePie/File.php index 6ecc9c1d9..1fcbde49b 100644 --- a/lib/SimplePie/SimplePie/File.php +++ b/lib/SimplePie/SimplePie/File.php @@ -113,11 +113,11 @@ class SimplePie_File curl_setopt($fp, CURLOPT_REFERER, SimplePie_Misc::url_remove_credentials($url)); curl_setopt($fp, CURLOPT_USERAGENT, $useragent); curl_setopt($fp, CURLOPT_HTTPHEADER, $headers2); - if (!ini_get('open_basedir') && !ini_get('safe_mode') && version_compare(SimplePie_Misc::get_curl_version(), '7.15.2', '>=')) - { - curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1); - curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects); - } + //if (!ini_get('open_basedir') && !ini_get('safe_mode') && version_compare(SimplePie_Misc::get_curl_version(), '7.15.2', '>=')) + //{ + // curl_setopt($fp, CURLOPT_FOLLOWLOCATION, 1); + // curl_setopt($fp, CURLOPT_MAXREDIRS, $redirects); + //} foreach ($curl_options as $curl_param => $curl_value) { curl_setopt($fp, $curl_param, $curl_value); } @@ -152,7 +152,7 @@ class SimplePie_File $this->redirects++; $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url); $previousStatusCode = $this->status_code; - $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen); + $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen, $curl_options, $syslog_enabled); $this->permanent_url = ($previousStatusCode == 301) ? $location : $url; return; } @@ -237,7 +237,7 @@ class SimplePie_File $this->redirects++; $location = SimplePie_Misc::absolutize_url($this->headers['location'], $url); $previousStatusCode = $this->status_code; - $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen); + $this->__construct($location, $timeout, $redirects, $headers, $useragent, $force_fsockopen, $curl_options, $syslog_enabled); $this->permanent_url = ($previousStatusCode == 301) ? $location : $url; return; } |
