Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 protected function doSendInternalRequest(InternalRequestInterface $internalRequest)
 {
     list($protocol, $host, $port, $path) = $this->parseUrl($url = (string) $internalRequest->getUrl());
     $socket = @stream_socket_client($protocol . '://' . $host . ':' . $port, $errno, $errstr, $this->getConfiguration()->getTimeout());
     if ($socket === false) {
         throw HttpAdapterException::cannotFetchUrl($url, $this->getName(), $errstr);
     }
     stream_set_timeout($socket, $this->getConfiguration()->getTimeout());
     fwrite($socket, $this->prepareRequest($internalRequest, $path, $host, $port));
     list($responseHeaders, $body) = $this->parseResponse($socket);
     $hasTimeout = $this->detectTimeout($socket);
     fclose($socket);
     if ($hasTimeout) {
         throw HttpAdapterException::timeoutExceeded($url, $this->getConfiguration()->getTimeout(), $this->getName());
     }
     return $this->getConfiguration()->getMessageFactory()->createResponse(StatusCodeExtractor::extract($responseHeaders), ReasonPhraseExtractor::extract($responseHeaders), ProtocolVersionExtractor::extract($responseHeaders), $responseHeaders = HeadersNormalizer::normalize($responseHeaders), BodyNormalizer::normalize($this->decodeBody($responseHeaders, $body), $internalRequest->getMethod()));
 }
Exemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 protected function sendInternalRequest(InternalRequestInterface $internalRequest)
 {
     $uri = $internalRequest->getUri();
     $socket = @stream_socket_client(($uri->getScheme() === 'https' ? 'ssl' : 'tcp') . '://' . $uri->getHost() . ':' . ($uri->getPort() ?: 80), $errno, $errstr, $this->getConfiguration()->getTimeout());
     if ($socket === false) {
         throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $errstr);
     }
     stream_set_timeout($socket, $this->getConfiguration()->getTimeout());
     fwrite($socket, $this->prepareRequest($internalRequest));
     list($responseHeaders, $body) = $this->parseResponse($socket);
     $hasTimeout = $this->detectTimeout($socket);
     fclose($socket);
     if ($hasTimeout) {
         throw HttpAdapterException::timeoutExceeded($uri, $this->getConfiguration()->getTimeout(), $this->getName());
     }
     return $this->getConfiguration()->getMessageFactory()->createResponse(StatusCodeExtractor::extract($responseHeaders), ProtocolVersionExtractor::extract($responseHeaders), $responseHeaders = HeadersNormalizer::normalize($responseHeaders), BodyNormalizer::normalize($this->decodeBody($responseHeaders, $body), $internalRequest->getMethod()));
 }