コード例 #1
0
 public function __construct(puzzle_message_RequestInterface $delegate)
 {
     $this->_delegate = $delegate;
     $stringUrl = $this->_delegate->getUrl();
     $puzzleUrl = puzzle_Url::fromString($stringUrl);
     $this->_url = new tubepress_url_impl_puzzle_PuzzleBasedUrl($puzzleUrl);
     parent::__construct($this->_delegate);
 }
コード例 #2
0
ファイル: CurlFactory.php プロジェクト: puzzlehttp/puzzle
 protected function getDefaultOptions(puzzle_message_RequestInterface $request, puzzle_adapter_curl_RequestMediator $mediator)
 {
     $url = $request->getUrl();
     // Strip fragment from URL. See:
     // https://github.com/guzzle/guzzle/issues/453
     if (($pos = strpos($url, '#')) !== false) {
         $url = substr($url, 0, $pos);
     }
     $config = $request->getConfig();
     $options = array(CURLOPT_URL => $url, CURLOPT_CONNECTTIMEOUT => $config['connect_timeout'] ? $config['connect_timeout'] : 150, CURLOPT_RETURNTRANSFER => false, CURLOPT_HEADER => false, CURLOPT_WRITEFUNCTION => array($mediator, 'writeResponseBody'), CURLOPT_HEADERFUNCTION => array($mediator, 'receiveResponseHeader'), CURLOPT_READFUNCTION => array($mediator, 'readRequestBody'), CURLOPT_HTTP_VERSION => $request->getProtocolVersion() === '1.0' ? CURL_HTTP_VERSION_1_0 : CURL_HTTP_VERSION_1_1, CURLOPT_SSL_VERIFYPEER => 1, CURLOPT_SSL_VERIFYHOST => 2, '_headers' => $request->getHeaders());
     if (defined('CURLOPT_PROTOCOLS')) {
         // Allow only HTTP and HTTPS protocols
         $options[CURLOPT_PROTOCOLS] = CURLPROTO_HTTP | CURLPROTO_HTTPS;
     }
     // cURL sometimes adds a content-type by default. Prevent this.
     if (!$request->hasHeader('Content-Type')) {
         $options[CURLOPT_HTTPHEADER][] = 'Content-Type:';
     }
     return $options;
 }
コード例 #3
0
 /**
  * Factory method to create a new exception with a normalized error message
  *
  * @param puzzle_message_RequestInterface  $request  Request
  * @param puzzle_message_ResponseInterface $response Response received
  * @param Exception        $previous Previous exception
  *
  * @return self
  */
 public static function create(puzzle_message_RequestInterface $request, puzzle_message_ResponseInterface $response = null, Exception $previous = null)
 {
     if (!$response) {
         return new self('Error completing request', $request, null, $previous);
     }
     $statusCode = $response->getStatusCode();
     $level = $statusCode[0];
     if ($level == '4') {
         $label = 'Client error response';
         $className = 'puzzle_exception_ClientException';
     } elseif ($level == '5') {
         $label = 'Server error response';
         $className = 'puzzle_exception_ServerException';
     } else {
         $label = 'Unsuccessful response';
         $className = __CLASS__;
     }
     $message = $label . ' [url] ' . $request->getUrl() . ' [status code] ' . $response->getStatusCode() . ' [reason phrase] ' . $response->getReasonPhrase();
     return new $className($message, $request, $response, $previous);
 }
コード例 #4
0
ファイル: Redirect.php プロジェクト: puzzlehttp/puzzle
 /**
  * Set the appropriate URL on the request based on the location header
  *
  * @param puzzle_message_RequestInterface  $redirectRequest
  * @param puzzle_message_ResponseInterface $response
  */
 private function setRedirectUrl(puzzle_message_RequestInterface $redirectRequest, puzzle_message_ResponseInterface $response)
 {
     $location = $response->getHeader('Location');
     $location = puzzle_Url::fromString($location);
     // Combine location with the original URL if it is not absolute.
     if (!$location->isAbsolute()) {
         $originalUrl = puzzle_Url::fromString($redirectRequest->getUrl());
         // Remove query string parameters and just take what is present on
         // the redirect Location header
         $originalUrl->getQuery()->clear();
         $location = $originalUrl->combine($location);
     }
     $redirectRequest->setUrl($location);
 }
コード例 #5
0
ファイル: StreamAdapter.php プロジェクト: puzzlehttp/puzzle
 private function createStreamResource(puzzle_message_RequestInterface $request, array $options, $context, &$http_response_header)
 {
     $this->_closure_createStreamResource_url = $request->getUrl();
     $this->_closure_createStreamResource_context = $context;
     return $this->createResource(array($this, '__callback_createStreamResource'), $request, $options);
 }