mirror of
https://github.com/friendica/friendica
synced 2024-11-11 14:22:54 +00:00
Fix redirect url in Guzzle Responses
This commit is contained in:
parent
e2ff48375f
commit
2234d6fa91
1 changed files with 19 additions and 5 deletions
|
@ -23,8 +23,8 @@ namespace Friendica\Network\HTTPClient\Response;
|
|||
|
||||
use Friendica\Core\Logger;
|
||||
use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses;
|
||||
use Friendica\Network\HTTPException\NotImplementedException;
|
||||
use GuzzleHttp\Psr7\Response;
|
||||
use GuzzleHttp\RedirectMiddleware;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
|
||||
/**
|
||||
|
@ -48,6 +48,11 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
|
|||
*/
|
||||
private $error;
|
||||
|
||||
/** @var string */
|
||||
private $redirectUrl = '';
|
||||
/** @var bool */
|
||||
private $isRedirectUrl = false;
|
||||
|
||||
public function __construct(ResponseInterface $response, string $url, $errorNumber = 0, $error = '')
|
||||
{
|
||||
parent::__construct($response->getStatusCode(), $response->getHeaders(), $response->getBody(), $response->getProtocolVersion(), $response->getReasonPhrase());
|
||||
|
@ -56,6 +61,7 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
|
|||
$this->errorNumber = $errorNumber;
|
||||
|
||||
$this->checkSuccess();
|
||||
$this->checkRedirect($response);
|
||||
}
|
||||
|
||||
private function checkSuccess()
|
||||
|
@ -78,6 +84,16 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
|
|||
}
|
||||
}
|
||||
|
||||
private function checkRedirect(ResponseInterface $response)
|
||||
{
|
||||
$headersRedirect = $response->getHeader(RedirectMiddleware::HISTORY_HEADER) ?? [];
|
||||
|
||||
if (count($headersRedirect) > 0) {
|
||||
$this->redirectUrl = $headersRedirect[0];
|
||||
$this->isRedirectUrl = true;
|
||||
}
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function getReturnCode(): string
|
||||
{
|
||||
|
@ -119,16 +135,14 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
|
|||
/** {@inheritDoc} */
|
||||
public function getRedirectUrl(): string
|
||||
{
|
||||
return $this->url;
|
||||
return $this->redirectUrl;
|
||||
}
|
||||
|
||||
/** {@inheritDoc}
|
||||
*
|
||||
* @throws NotImplementedException
|
||||
*/
|
||||
public function isRedirectUrl(): bool
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
return $this->isRedirectUrl;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
|
|
Loading…
Reference in a new issue