Skip to content

Commit

Permalink
Update RedirectHelper for path only location
Browse files Browse the repository at this point in the history
  • Loading branch information
korgocz authored and slischka committed Dec 20, 2022
1 parent 778ffb3 commit 09ffe8d
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/Fapi/HttpClient/RedirectHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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;
}
Expand Down

0 comments on commit 09ffe8d

Please sign in to comment.