Ejemplo n.º 1
0
 /**
  * Sets options on a cURL resource based on a request.
  */
 private static function setOptionsFromRequest($curl, RequestInterface $request)
 {
     $options = array(CURLOPT_HTTP_VERSION => $request->getProtocolVersion() == 1.0 ? CURL_HTTP_VERSION_1_0 : CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => $request->getMethod(), CURLOPT_URL => $request->getHost() . $request->getResource(), CURLOPT_HTTPHEADER => $request->getHeaders());
     switch ($request->getMethod()) {
         case RequestInterface::METHOD_HEAD:
             $options[CURLOPT_NOBODY] = true;
             break;
         case RequestInterface::METHOD_GET:
             $options[CURLOPT_HTTPGET] = true;
             break;
         case RequestInterface::METHOD_POST:
         case RequestInterface::METHOD_PUT:
         case RequestInterface::METHOD_DELETE:
         case RequestInterface::METHOD_PATCH:
         case RequestInterface::METHOD_OPTIONS:
             $options[CURLOPT_POSTFIELDS] = $fields = static::getPostFields($request);
             // remove the content-type header
             if (is_array($fields)) {
                 $options[CURLOPT_HTTPHEADER] = array_filter($options[CURLOPT_HTTPHEADER], function ($header) {
                     return 0 !== stripos($header, 'Content-Type: ');
                 });
             }
             break;
     }
     curl_setopt_array($curl, $options);
 }
Ejemplo n.º 2
0
 /**
  * Converts a request into an array for stream_context_create().
  *
  * @param RequestInterface $request A request object
  *
  * @return array An array for stream_context_create()
  */
 public function getStreamContextArray(RequestInterface $request)
 {
     $options = array('http' => array('method' => $request->getMethod(), 'header' => implode("\r\n", $request->getHeaders()), 'content' => $request->getContent(), 'protocol_version' => $request->getProtocolVersion(), 'ignore_errors' => $this->getIgnoreErrors(), 'max_redirects' => $this->getMaxRedirects(), 'timeout' => $this->getTimeout()), 'ssl' => array('verify_peer' => $this->getVerifyPeer()));
     if ($this->proxy) {
         $options['http']['proxy'] = $this->proxy;
         $options['http']['request_fulluri'] = true;
     }
     return $options;
 }
 /**
  * Reduces the request to its normal form
  * Which means: strip all information that does not contribute to its uniqueness
  * This will prevent cache misses, when effectively indifferent requests are made
  *
  * @param \Buzz\Message\RequestInterface $request
  * @return \Buzz\Message\RequestInterface
  */
 private function getNormalizedRequest(RequestInterface $request)
 {
     $normalizedRequest = clone $request;
     $headers = $request->getHeaders();
     $normalizedHeaders = $this->normalizeHeaders($headers);
     asort($normalizedHeaders);
     $normalizedRequest->setHeaders($normalizedHeaders);
     return $normalizedRequest;
 }
Ejemplo n.º 4
0
 /**
  * Converts a request into an array for stream_context_create().
  *
  * @param RequestInterface $request A request object
  *
  * @return array An array for stream_context_create()
  */
 public function getStreamContextArray(RequestInterface $request)
 {
     return array('http' => array('method' => $request->getMethod(), 'header' => implode("\r\n", $request->getHeaders()), 'content' => $request->getContent(), 'protocol_version' => $request->getProtocolVersion(), 'ignore_errors' => $this->getIgnoreErrors(), 'max_redirects' => $this->getMaxRedirects(), 'timeout' => $this->getTimeout()), 'ssl' => array('verify_peer' => $this->getVerifyPeer()));
 }
 public function postSend(RequestInterface $request, MessageInterface $response)
 {
     $this->data[] = array('request' => array('method' => $request->getMethod(), 'url' => sprintf('%s%s', $request->getHost(), $request->getResource()), 'headers' => $request->getHeaders(), 'content' => $request->getContent()), 'response' => array('statusCode' => $response->getStatusCode(), 'reasonPhrase' => $response->getReasonPhrase(), 'headers' => $response->getHeaders(), 'content' => $response->getContent()));
 }