From 09ffe8d7d1b3c190f7cc23d50ad70f73cda7822d Mon Sep 17 00:00:00 2001 From: David Flieger Date: Fri, 16 Dec 2022 08:48:41 +0100 Subject: [PATCH] Update RedirectHelper for path only location --- src/Fapi/HttpClient/RedirectHelper.php | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Fapi/HttpClient/RedirectHelper.php b/src/Fapi/HttpClient/RedirectHelper.php index aec5547..8dc3dfb 100644 --- a/src/Fapi/HttpClient/RedirectHelper.php +++ b/src/Fapi/HttpClient/RedirectHelper.php @@ -5,6 +5,7 @@ use GuzzleHttp\Psr7\Uri; use Psr\Http\Message\RequestInterface; use Psr\Http\Message\ResponseInterface; +use Psr\Http\Message\UriInterface; use function array_change_key_case; use function in_array; use function strlen; @@ -22,7 +23,7 @@ public static function followRedirects( ): ResponseInterface { for ($count = 0; $count < $limit; $count++) { - $redirectUrl = static::getRedirectUrl($response); + $redirectUrl = static::getRedirectUrl($response, $request->getUri()); if ($redirectUrl === null) { return $response; @@ -35,7 +36,7 @@ public static function followRedirects( throw new TooManyRedirectsException('Maximum number of redirections exceeded.'); } - private static function getRedirectUrl(ResponseInterface $httpResponse): ?string + private static function getRedirectUrl(ResponseInterface $httpResponse, UriInterface $requestUri): ?string { if (!static::isRedirectionStatusCode($httpResponse->getStatusCode())) { return null; @@ -47,6 +48,10 @@ private static function getRedirectUrl(ResponseInterface $httpResponse): ?string return null; } + if ($url[0] === '/') { + $url = $requestUri->getScheme() . '://' . $requestUri->getHost() . $url; + } + if (!static::isValidRedirectUrl($url)) { return null; }