/**
  * {@inheritdoc}
  *
  * @param string $url
  * @param array $options
  * @return Gass\Http\Stream
  */
 public function request($url = null, array $options = array())
 {
     parent::request($url, $options);
     $currentHeaders = $this->getOption('header');
     $headersArray = $currentHeaders === null ? array() : $this->parseHeaders($currentHeaders);
     if (null !== ($userAgent = $this->getUserAgent())) {
         $headersArray['User-Agent'] = $userAgent;
     }
     if (null !== ($acceptedLanguage = $this->getAcceptLanguage())) {
         $headersArray['Accepts-Language'] = $acceptedLanguage;
     }
     if (null !== ($remoteAddress = $this->getRemoteAddress())) {
         $headersArray['X-Forwarded-For'] = $remoteAddress;
     }
     $newHeaders = array();
     foreach ($headersArray as $key => $value) {
         $newHeaders[] = $key . ': ' . $value;
     }
     $headerString = implode("\r\n", $newHeaders);
     if (!empty($headerString)) {
         $this->setOption('header', $headerString);
     }
     $context = stream_context_create(parent::getOption('context'));
     if (false === ($response = @file_get_contents(parent::getOption('url'), false, $context))) {
         if (!isset($php_errormsg)) {
             $php_errormsg = 'error message not available, this could be because the ini ' . 'setting "track_errors" is set to "Off" or XDebug is running';
         }
         throw new Exception\RuntimeException('Source could not be retrieved. Error: ' . $php_errormsg);
     }
     $this->setResponseHeaders($http_response_header);
     if (null !== ($statusCode = $this->getInfo('Http-Code'))) {
         $this->checkResponseCode($statusCode);
     }
     $this->setResponse($response);
     return $this;
 }
 /**
  * {@inheritdoc}
  *
  * @param string $url
  * @param array $options
  * @return Gass\Http\Stream
  */
 public function request($url = null, array $options = array())
 {
     parent::request($url, $options);
     $url = $this->getBaseUrl($this->getOption('url'));
     $this->responseHeaders = array();
     if (!isset($this->requestQueue[$url])) {
         throw new Exception\OutOfBoundsException('No Test Http request info for requested url: ' . $this->getOption('url'));
     }
     $requestQueueItem = $this->requestQueue[$url];
     $this->setResponseHeaders($requestQueueItem['responseHeaders']);
     $this->setResponse($requestQueueItem['responseBody']);
     if (null !== ($statusCode = $this->getInfo('Http-Code'))) {
         $this->checkResponseCode($statusCode);
     }
     return $this;
 }
 /**
  * {@inheritdoc}
  *
  * @param string $url
  * @param array $options
  * @return Gass\Http\Curl
  */
 public function request($url = null, array $options = array())
 {
     parent::request($url, $options);
     $this->close();
     $this->curl = curl_init();
     if (null !== ($userAgent = $this->getUserAgent())) {
         $this->setOption(CURLOPT_USERAGENT, $userAgent);
     }
     $currentHeaders = $this->getOption(CURLOPT_HEADER);
     $extraHeaders = is_array($currentHeaders) ? $currentHeaders : array();
     if (null !== ($acceptedLanguage = $this->getAcceptLanguage())) {
         $extraHeaders[] = 'Accepts-Language: ' . $acceptedLanguage;
     }
     if (null !== ($remoteAddress = $this->getRemoteAddress())) {
         $extraHeaders[] = 'X-Forwarded-For: ' . $remoteAddress;
     }
     if (!empty($extraHeaders)) {
         $this->setOption(CURLOPT_HTTPHEADER, $extraHeaders);
     }
     $extraCurlOptions = $this->getOptions();
     if (!empty($extraCurlOptions) && false === curl_setopt_array($this->curl, $extraCurlOptions)) {
         throw new Exception\UnexpectedValueException('One of the extra curl options specified is invalid. Error: ' . curl_error($this->curl));
     }
     if (false === ($response = curl_exec($this->curl))) {
         throw new Exception\RuntimeException('Source could not be retrieved. Error: ' . curl_error($this->curl));
     }
     $statusCode = $this->getInfo(CURLINFO_HTTP_CODE);
     $this->checkResponseCode($statusCode);
     $this->setResponse($response);
     return $this;
 }