You are here

public function RedirectMiddleware::checkRedirect in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php \GuzzleHttp\RedirectMiddleware::checkRedirect()

Parameters

RequestInterface $request:

array $options:

ResponseInterface|PromiseInterface $response:

Return value

ResponseInterface|PromiseInterface

1 call to RedirectMiddleware::checkRedirect()
RedirectMiddleware::__invoke in vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php

File

vendor/guzzlehttp/guzzle/src/RedirectMiddleware.php, line 81

Class

RedirectMiddleware
Request redirect middleware.

Namespace

GuzzleHttp

Code

public function checkRedirect(RequestInterface $request, array $options, ResponseInterface $response) {
  if (substr($response
    ->getStatusCode(), 0, 1) != '3' || !$response
    ->hasHeader('Location')) {
    return $response;
  }
  $this
    ->guardMax($request, $options);
  $nextRequest = $this
    ->modifyRequest($request, $options, $response);
  if (isset($options['allow_redirects']['on_redirect'])) {
    call_user_func($options['allow_redirects']['on_redirect'], $request, $response, $nextRequest
      ->getUri());
  }

  /** @var PromiseInterface|ResponseInterface $promise */
  $promise = $this($nextRequest, $options);

  // Add headers to be able to track history of redirects.
  if (!empty($options['allow_redirects']['track_redirects'])) {
    return $this
      ->withTracking($promise, (string) $nextRequest
      ->getUri());
  }
  return $promise;
}