public function RedirectMiddleware::modifyRequest in Lockr 7.3
Parameters
RequestInterface $request:
array $options:
ResponseInterface $response:
Return value
1 call to RedirectMiddleware::modifyRequest()
- RedirectMiddleware::checkRedirect in vendor/
guzzlehttp/ guzzle/ src/ RedirectMiddleware.php
File
- vendor/
guzzlehttp/ guzzle/ src/ RedirectMiddleware.php, line 161
Class
- RedirectMiddleware
- Request redirect middleware.
Namespace
GuzzleHttpCode
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 && $request
->getBody() && !$options['allow_redirects']['strict']) {
$modify['method'] = 'GET';
$modify['body'] = '';
}
$modify['uri'] = $this
->redirectUri($request, $response, $protocols);
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);
}