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

@ -52,6 +52,8 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
private $redirectUrl = '';
/** @var bool */
private $isRedirectUrl = false;
/** @var bool */
private $redirectIsPermanent = false;
public function __construct(ResponseInterface $response, string $url, $errorNumber = 0, $error = '')
{
@ -91,6 +93,13 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
if (count($headersRedirect) > 0) {
$this->redirectUrl = $headersRedirect[0];
$this->isRedirectUrl = true;
$this->redirectIsPermanent = true;
foreach (($response->getHeader(RedirectMiddleware::STATUS_HISTORY_HEADER) ?? []) as $history) {
if (preg_match('/30(2|3|4|7)/', $history)) {
$this->redirectIsPermanent = false;
}
}
}
}
@ -145,6 +154,12 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
return $this->isRedirectUrl;
}
/** {@inheritDoc} */
public function redirectIsPermanent(): bool
{
return $this->redirectIsPermanent;
}
/** {@inheritDoc} */
public function getErrorNumber(): int
{