Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function createRedirectRequest(ResponseInterface $response, InternalRequestInterface $internalRequest, HttpAdapterInterface $httpAdapter)
 {
     if ($response->getStatusCode() < 300 || $response->getStatusCode() >= 400 || !$response->hasHeader('Location')) {
         return false;
     }
     if ($internalRequest->getParameter(self::REDIRECT_COUNT) >= $this->max) {
         if ($this->throwException) {
             throw HttpAdapterException::maxRedirectsExceeded((string) $this->getRootRequest($internalRequest)->getUrl(), $this->max, $httpAdapter->getName());
         }
         return false;
     }
     $redirect = $httpAdapter->getConfiguration()->getMessageFactory()->cloneInternalRequest($internalRequest);
     if ($response->getStatusCode() === 303 || !$this->strict && $response->getStatusCode() <= 302) {
         $redirect->setMethod(InternalRequestInterface::METHOD_GET);
         $redirect->removeHeaders(array('Content-Type', 'Content-Length'));
         $redirect->clearRawDatas();
         $redirect->clearDatas();
         $redirect->clearFiles();
     }
     $redirect->setUrl($response->getHeader('Location'));
     $redirect->setParameter(self::PARENT_REQUEST, $internalRequest);
     $redirect->setParameter(self::REDIRECT_COUNT, $internalRequest->getParameter(self::REDIRECT_COUNT) + 1);
     return $redirect;
 }
Beispiel #2
0
 /**
  * {@inheritdoc}
  */
 public function extract(InternalRequestInterface $request, ResponseInterface $response)
 {
     foreach ($response->getHeader('Set-Cookie') as $header) {
         $cookie = $this->cookieFactory->parse($header);
         if (!$cookie->hasAttribute(CookieInterface::ATTR_DOMAIN)) {
             $cookie->setAttribute(CookieInterface::ATTR_DOMAIN, $request->getUri()->getHost());
         }
         $this->addCookie($cookie);
     }
 }
Beispiel #3
0
 /**
  * {@inheritdoc}
  */
 public function createRedirectRequest(ResponseInterface $response, InternalRequestInterface $internalRequest, HttpAdapterInterface $httpAdapter)
 {
     if ($response->getStatusCode() < 300 || $response->getStatusCode() >= 400 || !$response->hasHeader('Location')) {
         return false;
     }
     if ($internalRequest->getParameter(self::REDIRECT_COUNT) >= $this->max) {
         if ($this->throwException) {
             throw HttpAdapterException::maxRedirectsExceeded((string) $this->getRootRequest($internalRequest)->getUri(), $this->max, $httpAdapter->getName());
         }
         return false;
     }
     $strict = $response->getStatusCode() === 303 || !$this->strict && $response->getStatusCode() <= 302;
     $headers = $internalRequest->getHeaders();
     foreach ($headers as $key => $value) {
         if (strtolower($key) === 'host') {
             unset($headers[$key]);
         }
     }
     $redirect = $httpAdapter->getConfiguration()->getMessageFactory()->createInternalRequest($response->getHeader('Location'), $strict ? InternalRequestInterface::METHOD_GET : $internalRequest->getMethod(), $internalRequest->getProtocolVersion(), $headers, $strict ? array() : $internalRequest->getDatas(), $strict ? array() : $internalRequest->getFiles(), $internalRequest->getParameters());
     if ($strict) {
         $redirect = $redirect->withoutHeader('Content-Type')->withoutHeader('Content-Length');
     } else {
         $redirect = $redirect->withBody($internalRequest->getBody());
     }
     return $redirect->withParameter(self::PARENT_REQUEST, $internalRequest)->withParameter(self::REDIRECT_COUNT, $internalRequest->getParameter(self::REDIRECT_COUNT) + 1);
 }