Merge pull request #14267 from mexon/mat/permanent-redirect

Update feed URL after permanent redirect
This commit is contained in:
Michael Vogel 2024-07-03 09:33:10 +02:00 committed by GitHub
commit 491a5cab53
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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 = end($headersRedirect);
$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
{