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;
/**
*/
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());
$this->errorNumber = $errorNumber;
$this->checkSuccess();
+ $this->checkRedirect($response);
}
private function checkSuccess()
}
}
+ 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
{
/** {@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} */