mirror of
https://github.com/friendica/friendica
synced 2024-12-23 08:00:16 +00:00
Merge pull request #11083 from nupplaphil/bug/11078
Fix redirect url in Guzzle Responses
This commit is contained in:
commit
6a813eec92
1 changed files with 19 additions and 5 deletions
|
@ -23,8 +23,8 @@ namespace Friendica\Network\HTTPClient\Response;
|
||||||
|
|
||||||
use Friendica\Core\Logger;
|
use Friendica\Core\Logger;
|
||||||
use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses;
|
use Friendica\Network\HTTPClient\Capability\ICanHandleHttpResponses;
|
||||||
use Friendica\Network\HTTPException\NotImplementedException;
|
|
||||||
use GuzzleHttp\Psr7\Response;
|
use GuzzleHttp\Psr7\Response;
|
||||||
|
use GuzzleHttp\RedirectMiddleware;
|
||||||
use Psr\Http\Message\ResponseInterface;
|
use Psr\Http\Message\ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -48,6 +48,11 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
|
||||||
*/
|
*/
|
||||||
private $error;
|
private $error;
|
||||||
|
|
||||||
|
/** @var string */
|
||||||
|
private $redirectUrl = '';
|
||||||
|
/** @var bool */
|
||||||
|
private $isRedirectUrl = false;
|
||||||
|
|
||||||
public function __construct(ResponseInterface $response, string $url, $errorNumber = 0, $error = '')
|
public function __construct(ResponseInterface $response, string $url, $errorNumber = 0, $error = '')
|
||||||
{
|
{
|
||||||
parent::__construct($response->getStatusCode(), $response->getHeaders(), $response->getBody(), $response->getProtocolVersion(), $response->getReasonPhrase());
|
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->errorNumber = $errorNumber;
|
||||||
|
|
||||||
$this->checkSuccess();
|
$this->checkSuccess();
|
||||||
|
$this->checkRedirect($response);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function checkSuccess()
|
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} */
|
/** {@inheritDoc} */
|
||||||
public function getReturnCode(): string
|
public function getReturnCode(): string
|
||||||
{
|
{
|
||||||
|
@ -119,16 +135,14 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
public function getRedirectUrl(): string
|
public function getRedirectUrl(): string
|
||||||
{
|
{
|
||||||
return $this->url;
|
return $this->redirectUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc}
|
/** {@inheritDoc}
|
||||||
*
|
|
||||||
* @throws NotImplementedException
|
|
||||||
*/
|
*/
|
||||||
public function isRedirectUrl(): bool
|
public function isRedirectUrl(): bool
|
||||||
{
|
{
|
||||||
throw new NotImplementedException();
|
return $this->isRedirectUrl;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** {@inheritDoc} */
|
/** {@inheritDoc} */
|
||||||
|
|
Loading…
Reference in a new issue