Skip to content

Commit

Permalink
Pass response to TooManyRedirectsException
Browse files Browse the repository at this point in the history
  • Loading branch information
davidgrayston committed May 24, 2020
1 parent d2db8f5 commit 75b2b3a
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/RedirectMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function checkRedirect(
return $response;
}

$this->guardMax($request, $options);
$this->guardMax($request, $response, $options);
$nextRequest = $this->modifyRequest($request, $options, $response);

if (isset($options['allow_redirects']['on_redirect'])) {
Expand Down Expand Up @@ -135,7 +135,7 @@ function (ResponseInterface $response) use ($uri, $statusCode) {
*
* @throws TooManyRedirectsException Too many redirects.
*/
private function guardMax(RequestInterface $request, array &$options): void
private function guardMax(RequestInterface $request, ResponseInterface $response, array &$options): void
{
$current = isset($options['__redirect_count'])
? $options['__redirect_count']
Expand All @@ -146,7 +146,8 @@ private function guardMax(RequestInterface $request, array &$options): void
if ($options['__redirect_count'] > $max) {
throw new TooManyRedirectsException(
"Will not follow more than {$max} redirects",
$request
$request,
$response
);
}
}
Expand Down

0 comments on commit 75b2b3a

Please sign in to comment.