예제 #1
0
 /**
  * Create a canonicalized AmzHeaders string for a signature.
  *
  * @param RequestInterface $request Request from which to gather headers
  *
  * @return string Returns canonicalized AMZ headers.
  */
 private function createCanonicalizedAmzHeaders(RequestInterface $request)
 {
     $headers = array();
     foreach ($request->getHeaders() as $name => $header) {
         $name = strtolower($name);
         if (strpos($name, 'x-amz-') === 0) {
             $value = trim((string) $header);
             if ($value || $value === '0') {
                 $headers[$name] = $name . ':' . $value;
             }
         }
     }
     if (!$headers) {
         return '';
     }
     ksort($headers);
     return implode("\n", $headers) . "\n";
 }
예제 #2
0
 private function moveHeadersToQuery(RequestInterface $request)
 {
     $query = $request->getQuery();
     foreach ($request->getHeaders() as $name => $header) {
         if (substr($name, 0, 5) == 'x-amz') {
             $query[$header->getName()] = (string) $header;
         }
         if ($name !== 'host') {
             $request->removeHeader($name);
         }
     }
 }
예제 #3
0
 /**
  * Clone a request while changing the method. Emulates the behavior of
  * {@see Guzzle\Http\Message\Request::clone}, but can change the HTTP method.
  *
  * @param RequestInterface $request Request to clone
  * @param string           $method  Method to set
  *
  * @return RequestInterface
  */
 public function cloneRequestWithMethod(RequestInterface $request, $method)
 {
     // Create the request with the same client if possible
     if ($request->getClient()) {
         $cloned = $request->getClient()->createRequest($method, $request->getUrl(), $request->getHeaders());
     } else {
         $cloned = $this->create($method, $request->getUrl(), $request->getHeaders());
     }
     $cloned->getCurlOptions()->replace($request->getCurlOptions()->toArray());
     $cloned->setEventDispatcher(clone $request->getEventDispatcher());
     // Ensure that that the Content-Length header is not copied if changing to GET or HEAD
     if (!$cloned instanceof EntityEnclosingRequestInterface) {
         $cloned->removeHeader('Content-Length');
     } elseif ($request instanceof EntityEnclosingRequestInterface) {
         $cloned->setBody($request->getBody());
     }
     $cloned->getParams()->replace($request->getParams()->toArray());
     $cloned->dispatch('request.clone', array('request' => $cloned));
     return $cloned;
 }