/**
  * Perform handling of the given request.
  *
  * @param org_tubepress_api_http_HttpRequest $request The HTTP request.
  *
  * @return void
  */
 protected function handleRequest(org_tubepress_api_http_HttpRequest $request)
 {
     org_tubepress_impl_log_Log::log($this->logPrefix(), 'Calling fopen()...');
     $this->_handle = @fopen($request->getUrl()->toString(), self::$_fopen_readonly);
     if ($this->_handle === false) {
         throw new Exception(sprintf('Could not open handle for fopen() to %s', $request->getUrl()));
     }
     org_tubepress_impl_log_Log::log($this->logPrefix(), 'Successfully opened stream');
     stream_set_timeout($this->_handle, 5);
     $rawContent = '';
     while (!feof($this->_handle)) {
         $rawContent .= fread($this->_handle, 4096);
     }
     org_tubepress_impl_log_Log::log($this->logPrefix(), 'Done reading stream');
     if (function_exists('stream_get_meta_data')) {
         org_tubepress_impl_log_Log::log($this->logPrefix(), 'Asking for stream metadata');
         $meta = stream_get_meta_data($this->_handle);
         $rawHeaders = $meta[self::$_meta_wrapper];
         if (isset($meta[self::$_meta_wrapper][self::$_meta_wrapper_info])) {
             $rawHeaders = $meta[self::$_meta_wrapper][self::$_meta_wrapper_info];
         }
     } else {
         org_tubepress_impl_log_Log::log($this->logPrefix(), 'stream_get_meta_data() does not exist');
         //$http_response_header is a PHP reserved variable which is set in the current-scope when using the HTTP Wrapper
         //see http://php.oregonstate.edu/manual/en/reserved.variables.httpresponseheader.php
         $rawHeaders = $http_response_header;
     }
     return implode("\r\n", $rawHeaders) . "\r\n\r\n" . $rawContent;
 }
 /**
  * Determines if this transport can handle the given request.
  *
  * @param org_tubepress_api_http_HttpRequest $request The request to handle.
  *
  * @return bool True if this transport can handle the given request. False otherwise.
  */
 function canHandle(org_tubepress_api_http_HttpRequest $request)
 {
     $scheme = $request->getUrl()->getScheme();
     return preg_match_all('/https?/', $scheme, $matches) === 1;
 }
 private function _setCurlOptions(org_tubepress_api_http_HttpRequest $request)
 {
     curl_setopt_array($this->_handle, array(CURLOPT_CONNECTTIMEOUT => 5, CURLOPT_HEADER => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0, CURLOPT_MAXREDIRS => 5, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYHOST => true, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_TIMEOUT => 5, CURLOPT_URL => $request->getUrl()->toString(), CURLOPT_USERAGENT => $request->getHeaderValue(org_tubepress_api_http_HttpRequest::HTTP_HEADER_USER_AGENT)));
     $this->_setCurlOptionsFollowLocation();
     $this->_setCurlOptionsBody($request);
     $this->_setCurlOptionsHeaders($request);
 }
 private static function _buildHeaderString(org_tubepress_api_http_HttpRequest $request)
 {
     $url = $request->getUrl();
     $path = $url->getPath();
     $query = $url->getQuery();
     $host = $url->getHost();
     $entity = $request->getEntity();
     $headerArray = $request->getAllHeaders();
     $toRequest = '/';
     if ($path !== null) {
         $toRequest = $path;
     }
     if ($query !== null) {
         $toRequest .= '?' . $query;
     }
     /** Use HTTP 1.0 unless you want this to run SLOW. */
     $strHeaders = $request->getMethod() . " {$toRequest} HTTP/1.0\r\n";
     $strHeaders .= "Host: {$host}\r\n";
     foreach ($headerArray as $name => $value) {
         $strHeaders .= "{$name}: {$value}\r\n";
     }
     $strHeaders .= "\r\n";
     if ($entity !== null && $entity->getContent() !== null) {
         $strHeaders .= $entity->getContent();
     }
     return $strHeaders;
 }
 private static function _checkRequest(org_tubepress_api_http_HttpRequest $request)
 {
     if ($request->getMethod() === null) {
         throw new Exception('Request has no method set');
     }
     if ($request->getUrl() === null) {
         throw new Exception('Request has no URL set');
     }
 }