Example #1
0
 protected function prepareRedirection(RequestInterface $original, RequestInterface $request, Response $response)
 {
     $params = $original->getParams();
     $current = $params[self::REDIRECT_COUNT] + 1;
     $params[self::REDIRECT_COUNT] = $current;
     $max = isset($params[self::MAX_REDIRECTS]) ? $params[self::MAX_REDIRECTS] : $this->defaultMaxRedirects;
     if ($current > $max) {
         $this->throwTooManyRedirectsException($original, $max);
         return false;
     } else {
         return $this->createRedirectRequest($request, $response->getStatusCode(), trim($response->getLocation()), $original);
     }
 }
Example #2
0
 /**
  * Prepare the request for redirection and enforce the maximum number of allowed redirects per client
  *
  * @param RequestInterface $original  Original request
  * @param RequestInterface $request   Request to prepare and validate
  * @param Response         $response  The current response
  *
  * @return RequestInterface
  */
 protected function prepareRedirection(RequestInterface $original, RequestInterface $request, Response $response)
 {
     $params = $original->getParams();
     // This is a new redirect, so increment the redirect counter
     $current = $params[self::REDIRECT_COUNT] + 1;
     $params[self::REDIRECT_COUNT] = $current;
     // Use a provided maximum value or default to a max redirect count of 5
     $max = isset($params[self::MAX_REDIRECTS]) ? $params[self::MAX_REDIRECTS] : $this->defaultMaxRedirects;
     // Throw an exception if the redirect count is exceeded
     if ($current > $max) {
         $this->throwTooManyRedirectsException($original, $max);
         return false;
     } else {
         // Create a redirect request based on the redirect rules set on the request
         return $this->createRedirectRequest($request, $response->getStatusCode(), trim($response->getLocation()), $original);
     }
 }
 /**
  * 
  * @param \Guzzle\Http\Message\Response $response
  * @return string
  */
 private function getResponseLocation(\Guzzle\Http\Message\Response $response)
 {
     $absoluteUrlDeriver = new \webignition\AbsoluteUrlDeriver\AbsoluteUrlDeriver($response->getLocation(), $this->currentUrl);
     return (string) $absoluteUrlDeriver->getAbsoluteUrl();
 }