コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function toJson(array $config = array())
 {
     $body = (string) $this->getBody();
     if (!$body) {
         return;
     }
     return $this->_delegate->json($config);
 }
コード例 #2
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);
 }
コード例 #3
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);
 }
コード例 #4
0
ファイル: CookieJar.php プロジェクト: puzzlehttp/puzzle
 public function extractCookies(puzzle_message_RequestInterface $request, puzzle_message_ResponseInterface $response)
 {
     if ($cookieHeader = $response->getHeader('Set-Cookie', true)) {
         foreach ($cookieHeader as $cookie) {
             $sc = puzzle_cookie_SetCookie::fromString($cookie);
             if (!$sc->getDomain()) {
                 $sc->setDomain($request->getHost());
             }
             $this->setCookie($sc);
         }
     }
 }