You are here

public function RedirectMiddleware::modifyRequest in Auth0 Single Sign On 8.2

Parameters

RequestInterface $request:

array $options:

ResponseInterface $response:

Return value

RequestInterface

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

File

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

Class

RedirectMiddleware
Request redirect middleware.

Namespace

GuzzleHttp

Code

public function modifyRequest(RequestInterface $request, array $options, ResponseInterface $response) {

  // Request modifications to apply.
  $modify = [];
  $protocols = $options['allow_redirects']['protocols'];

  // Use a GET request if this is an entity enclosing request and we are
  // not forcing RFC compliance, but rather emulating what all browsers
  // would do.
  $statusCode = $response
    ->getStatusCode();
  if ($statusCode == 303 || $statusCode <= 302 && !$options['allow_redirects']['strict']) {
    $modify['method'] = 'GET';
    $modify['body'] = '';
  }
  $uri = $this
    ->redirectUri($request, $response, $protocols);
  if (isset($options['idn_conversion']) && $options['idn_conversion'] !== false) {
    $idnOptions = $options['idn_conversion'] === true ? IDNA_DEFAULT : $options['idn_conversion'];
    $uri = Utils::idnUriConvert($uri, $idnOptions);
  }
  $modify['uri'] = $uri;
  Psr7\rewind_body($request);

  // Add the Referer header if it is told to do so and only
  // add the header if we are not redirecting from https to http.
  if ($options['allow_redirects']['referer'] && $modify['uri']
    ->getScheme() === $request
    ->getUri()
    ->getScheme()) {
    $uri = $request
      ->getUri()
      ->withUserInfo('');
    $modify['set_headers']['Referer'] = (string) $uri;
  }
  else {
    $modify['remove_headers'][] = 'Referer';
  }

  // Remove Authorization header if host is different.
  if ($request
    ->getUri()
    ->getHost() !== $modify['uri']
    ->getHost()) {
    $modify['remove_headers'][] = 'Authorization';
  }
  return Psr7\modify_request($request, $modify);
}