Update feed URL after permanent redirect

This commit is contained in:
Matthew Exon 2024-07-01 18:50:13 +02:00
parent 918317fa49
commit 31f103a1f0
5 changed files with 63 additions and 2 deletions

View file

@ -81,6 +81,11 @@ class CurlResult implements ICanHandleHttpResponses
*/
private $isRedirectUrl;
/**
* @var boolean true if the URL has a permanent redirect
*/
private $redirectIsPermanent;
/**
* @var boolean true if the curl request timed out
*/
@ -197,7 +202,7 @@ class CurlResult implements ICanHandleHttpResponses
$this->redirectUrl = $this->info['url'];
}
if ($this->returnCode == 301 || $this->returnCode == 302 || $this->returnCode == 303 || $this->returnCode == 307) {
if ($this->returnCode == 301 || $this->returnCode == 302 || $this->returnCode == 303 || $this->returnCode == 307 || $this->returnCode == 308) {
$redirect_parts = parse_url($this->info['redirect_url'] ?? '');
if (empty($redirect_parts)) {
$redirect_parts = [];
@ -224,10 +229,11 @@ class CurlResult implements ICanHandleHttpResponses
}
$this->redirectUrl = (string)Uri::fromParts((array)$redirect_parts);
$this->isRedirectUrl = true;
$this->redirectIsPermanent = $this->returnCode == 301 or $this->returnCode == 308;
} else {
$this->isRedirectUrl = false;
$this->redirectIsPermanent = false;
}
}
@ -340,6 +346,12 @@ class CurlResult implements ICanHandleHttpResponses
return $this->isRedirectUrl;
}
/** {@inheritDoc} */
public function redirectIsPermanent(): bool
{
return $this->redirectIsPermanent;
}
/** {@inheritDoc} */
public function getErrorNumber(): int
{