protected function RedirectPlugin::prepareRedirection

Prepare the request for redirection and enforce the maximum number of allowed redirects per client

Parameters

RequestInterface $request Request to prepare and validate:

Return value

RequestInterface Returns the original request

1 call to RedirectPlugin::prepareRedirection()
RedirectPlugin::onRequestSent in drupal/core/vendor/guzzle/http/Guzzle/Http/RedirectPlugin.php
Called when a request receives a redirect response

File

drupal/core/vendor/guzzle/http/Guzzle/Http/RedirectPlugin.php, line 173

Class

RedirectPlugin
Plugin to implement HTTP redirects. Can redirect like a web browser or using strict RFC 2616 compliance

Namespace

Guzzle\Http

Code

protected function prepareRedirection(RequestInterface $request) {
  $original = $request;

  // The number of redirects is held on the original request, so determine which request that is
  while ($parent = $original
    ->getParams()
    ->get(self::PARENT_REQUEST)) {
    $original = $parent;
  }

  // Always associate the parent response with the current response so that a chain can be established
  if ($parent = $request
    ->getParams()
    ->get(self::PARENT_REQUEST)) {
    $request
      ->getResponse()
      ->setPreviousResponse($parent
      ->getResponse());
  }
  $params = $original
    ->getParams();

  // This is a new redirect, so increment the redirect counter
  $current = $params
    ->get(self::REDIRECT_COUNT) + 1;
  $params
    ->set(self::REDIRECT_COUNT, $current);

  // Use a provided maximum value or default to a max redirect count of 5
  $max = $params
    ->hasKey(self::MAX_REDIRECTS) ? $params
    ->get(self::MAX_REDIRECTS) : $this->defaultMaxRedirects;

  // Throw an exception if the redirect count is exceeded
  if ($current > $max) {
    return $this
      ->throwTooManyRedirectsException($request);
  }
  return $original;
}