Exemplo n.º 1
0
 public function testGetUrlFormatsAUrl()
 {
     $request = new Request();
     $request->setHost('http://example.com');
     $request->setResource('/resource/123');
     $this->assertEquals('http://example.com/resource/123', $request->getUrl());
 }
Exemplo n.º 2
0
 /**
  * Authenticate the request object. Apply the access_token to the URL
  *
  * TODO: implement
  * 
  * @param Request       $request        Request object to authenticate
  */
 public function authenticate(\Buzz\Message\Request $request)
 {
     $url = $request->getUrl();
     $prefix = strpos($url, '?') > 0 ? '&' : '?';
     $request->fromUrl($url . $prefix . 'access_token=' . $this->accessToken);
     return $request;
 }
Exemplo n.º 3
0
 protected static function setCurlOptsFromRequest($curl, Message\Request $request)
 {
     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->getMethod());
     curl_setopt($curl, CURLOPT_URL, $request->getUrl());
     curl_setopt($curl, CURLOPT_HTTPHEADER, $request->getHeaders());
     curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getContent());
 }
Exemplo n.º 4
0
 /**
  * @param Request $request
  * @param Response $response
  * 
  * @return HttpException
  */
 public static function factory(Request $request, Response $response)
 {
     if ($response->isClientError()) {
         $label = 'Client error response';
     } elseif ($response->isServerError()) {
         $label = 'Server error response';
     } else {
         $label = 'Unsuccessful response';
     }
     $message = implode(PHP_EOL, array($label, '[status code] ' . $response->getStatusCode(), '[reason phrase] ' . $response->getReasonPhrase(), '[url] ' . $request->getUrl()));
     $e = new static($message, $response->getStatusCode());
     $e->setResponse($response);
     $e->setRequest($request);
     return $e;
 }
Exemplo n.º 5
0
Arquivo: Curl.php Projeto: kingsj/core
 protected static function setCurlOptsFromRequest($curl, Message\Request $request)
 {
     $options = array(CURLOPT_CUSTOMREQUEST => $request->getMethod(), CURLOPT_URL => $request->getUrl(), CURLOPT_HTTPHEADER => $request->getHeaders(), CURLOPT_HTTPGET => false, CURLOPT_NOBODY => false, CURLOPT_POSTFIELDS => null);
     switch ($request->getMethod()) {
         case Message\Request::METHOD_HEAD:
             $options[CURLOPT_NOBODY] = true;
             break;
         case Message\Request::METHOD_GET:
             $options[CURLOPT_HTTPGET] = true;
             break;
         case Message\Request::METHOD_POST:
         case Message\Request::METHOD_PUT:
             $options[CURLOPT_POSTFIELDS] = $fields = self::getPostFields($request);
             // remove the content-type header
             if (is_array($fields)) {
                 $options[CURLOPT_HTTPHEADER] = array_filter($options[CURLOPT_HTTPHEADER], function ($header) {
                     return 0 !== strpos($header, 'Content-Type: ');
                 });
             }
             break;
     }
     curl_setopt_array($curl, $options);
 }
Exemplo n.º 6
0
 public function postSend(Message\Request $request, Message\Response $response)
 {
     $seconds = microtime(true) - $this->startTime;
     call_user_func($this->logger, sprintf('%sSent "%s %s" in %dms', $this->prefix, $request->getMethod(), $request->getUrl(), round($seconds * 1000)));
 }