private function _canHandle(ehough_shortstop_api_HttpRequest $request, ehough_shortstop_api_HttpResponse $response) { $url = $request->getUrl(); $host = $url->getHost(); if (!tubepress_impl_util_StringUtils::endsWith($host, 'youtube.com')) { return false; } $contentType = $response->getHeaderValue('Content-Type'); $entity = $response->getEntity(); return $entity && $contentType === 'application/vnd.google.gdata.error+xml'; }
/** * Perform handling of the given request. * * @param ehough_shortstop_api_HttpRequest $request The HTTP request. * * @throws ehough_shortstop_api_exception_RuntimeException If something goes wrong. * * @return string The raw response for this request. May be empty or null. */ protected function handleRequest(ehough_shortstop_api_HttpRequest $request) { $isDebugging = $this->_logger->isHandling(ehough_epilog_Logger::DEBUG); if ($isDebugging) { $this->_logger->debug('Calling fopen()...'); } $this->_handle = @fopen($request->getUrl()->toString(), self::$_fopen_readonly); if ($this->_handle === false) { throw new ehough_shortstop_api_exception_RuntimeException(sprintf('Could not open handle for fopen() to %s', $request->getUrl())); } if ($isDebugging) { $this->_logger->debug('Successfully opened stream'); } stream_set_timeout($this->_handle, 15); $rawContent = ''; while (!feof($this->_handle)) { $rawContent .= fread($this->_handle, 4096); } if ($isDebugging) { $this->_logger->debug('Done reading stream'); } if (function_exists('stream_get_meta_data')) { if ($isDebugging) { $this->_logger->debug('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 { if ($isDebugging) { $this->_logger->debug('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; }
private function _getSignature(ehough_shortstop_api_HttpRequest $request, array $baseOAuthParams, ehough_coauthor_api_v1_Credentials $clientCredentials, ehough_coauthor_api_v1_Credentials $tokenCredentials = null) { $url = $request->getUrl(); $existingQueryParams = $url->getQueryVariables(); $signatureData = array_merge($existingQueryParams, $baseOAuthParams); foreach ($signatureData as $key => $value) { $signatureData[$this->_urlEncode($key)] = $this->_urlEncode($value); } uksort($signatureData, 'strcmp'); $baseUrl = $url->getScheme() . '://' . $this->_getNormalizedAuthority($url) . $url->getPath(); $baseStringParts = $this->_urlEncode(array($request->getMethod(), $baseUrl, $this->_concatParams($signatureData))); $baseString = implode('&', $baseStringParts); $keyParts = $this->_urlEncode(array($clientCredentials->getSecret(), $tokenCredentials === null ? '' : $tokenCredentials->getSecret())); $signingKey = implode('&', $keyParts); $signature = base64_encode($this->_hash($baseString, $signingKey)); return $signature; }
private function _canHandle(ehough_shortstop_api_HttpRequest $request, ehough_shortstop_api_HttpResponse $response) { $url = $request->getUrl(); $host = $url->getHost(); return tubepress_impl_util_StringUtils::endsWith($host, 'vimeo.com'); }
private static function _buildHeaderString(ehough_shortstop_api_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; }
/** * Determines if this transport can handle the given request. * * @param ehough_shortstop_api_HttpRequest $request The request to handle. * * @return bool True if this transport can handle the given request. False otherwise. */ public function canHandle(ehough_shortstop_api_HttpRequest $request) { $scheme = $request->getUrl()->getScheme(); return preg_match_all('/https?/', $scheme, $matches) === 1; }
private function _setCurlOptions(ehough_shortstop_api_HttpRequest $request) { curl_setopt_array($this->_handle, array(CURLOPT_CONNECTTIMEOUT => 15, CURLOPT_HEADER => true, CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_0, CURLOPT_MAXREDIRS => 5, CURLOPT_RETURNTRANSFER => true, CURLOPT_SSL_VERIFYHOST => 2, CURLOPT_SSL_VERIFYPEER => true, CURLOPT_TIMEOUT => 15, CURLOPT_URL => $request->getUrl()->toString(), CURLOPT_USERAGENT => $request->getHeaderValue(ehough_shortstop_api_HttpRequest::HTTP_HEADER_USER_AGENT))); $this->_setCurlOptionsFollowLocation(); $this->_setCurlOptionsBody($request); $this->_setCurlOptionsHeaders($request); }