private function onResponseRedirect(ResponseInterface $response, RequestInterface $request)
{
// resolve location relative to last request URI
$location = $this->messageFactory->uriRelative($request->getUri(), $response->getHeaderLine('Location'));
// naïve approach..
$method = $request->getMethod() === 'HEAD' ? 'HEAD' : 'GET';
$request = $this->messageFactory->request($method, $location);
$this->progress('redirect', array($request));
if ($this->numRequests >= $this->maxRedirects) {
throw new \RuntimeException('Maximum number of redirects (' . $this->maxRedirects . ') exceeded');
}
return $this->next($request);
}