You are here

public function RedirectMiddleware::__invoke in Zircon Profile 8.0

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

Parameters

RequestInterface $request:

array $options:

Return value

PromiseInterface

File

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

Class

RedirectMiddleware
Request redirect middleware.

Namespace

GuzzleHttp

Code

public function __invoke(RequestInterface $request, array $options) {
  $fn = $this->nextHandler;
  if (empty($options['allow_redirects'])) {
    return $fn($request, $options);
  }
  if ($options['allow_redirects'] === true) {
    $options['allow_redirects'] = self::$defaultSettings;
  }
  elseif (!is_array($options['allow_redirects'])) {
    throw new \InvalidArgumentException('allow_redirects must be true, false, or array');
  }
  else {

    // Merge the default settings with the provided settings
    $options['allow_redirects'] += self::$defaultSettings;
  }
  if (empty($options['allow_redirects']['max'])) {
    return $fn($request, $options);
  }
  return $fn($request, $options)
    ->then(function (ResponseInterface $response) use ($request, $options) {
    return $this
      ->checkRedirect($request, $options, $response);
  });
}