/**
* @param $result
* @return mixed
*/
protected function redirectIfNecessary($result, $maxRedirects, $redirectCount)
{
$locationHeader = $this->client->getInternalResponse()->getHeader('Location');
if ($locationHeader) {
if ($redirectCount == $maxRedirects) {
throw new \LogicException(sprintf('The maximum number (%d) of redirections was reached.', $maxRedirects));
}
$this->debugSection('Redirecting to', $locationHeader);
$result = $this->client->followRedirect();
$this->debugResponse($locationHeader);
return $this->redirectIfNecessary($result, $maxRedirects, $redirectCount + 1);
}
$this->client->followRedirects(true);
return $result;
}