/**
  * @param ClientRequest $clientRequest
  * @return Response
  */
 public function getResponse(ClientRequest $clientRequest)
 {
     $client = new HttpClient();
     $headers = array();
     foreach ($clientRequest->getHeaders() as $key => $val) {
         $headers[] = "{$key}: {$val}";
     }
     switch ($clientRequest->getVerb()) {
         case ClientRequest::POST:
             $response = $client->post(array('url' => $clientRequest->getUrl(), 'content' => $clientRequest->getContent(), 'headers' => $headers));
             break;
         case ClientRequest::DELETE:
             $response = $client->delete(array('url' => $clientRequest->getUrl(), 'headers' => $headers));
             break;
         case ClientRequest::PUT:
             $response = $client->put(array('url' => $clientRequest->getUrl(), 'content' => $clientRequest->getContent(), 'headers' => $headers));
             break;
         case ClientRequest::GET:
         default:
             $response = $client->get(array('url' => $clientRequest->getUrl(), 'params' => $clientRequest->getParameters(), 'headers' => $headers));
             break;
     }
     if ($response instanceof \Vinelab\Http\Response) {
         $content = $response->content();
         if (is_bool($content) || is_null($content)) {
             $content = '';
         }
         $responseBag = new Response($content, $response->statusCode(), $response->headers());
         return $responseBag;
     } else {
         return null;
     }
 }
 public function handle(HTTPApiClient $apiClient, ClientRequest $clientRequest)
 {
     if (!$apiClient instanceof Client) {
         return $clientRequest;
     }
     $content_md5 = base64_encode(md5($clientRequest->getContent()));
     $gmt_date = Util::getGMTDate();
     $clientRequest->setHeader('x-mqs-version', static::X_MQS_VERSION);
     $canonicalizedMQSHeaders = array();
     foreach ($clientRequest->getHeaders() as $key => $value) {
         if (preg_match('/^x\\-mqs\\-/', $key)) {
             $canonicalizedMQSHeaders[$key] = $value;
         }
     }
     ksort($canonicalizedMQSHeaders, SORT_STRING);
     $sign = Util::getSignature($clientRequest->getVerb(), $content_md5, static::CONTENT_TYPE, $gmt_date, $canonicalizedMQSHeaders, $clientRequest->getUrl(), $apiClient->getAccessKey(), $apiClient->getAccessSecret());
     $clientRequest->setHeader('Host', $apiClient->getQueueOwnerId() . "." . $apiClient->getMqsUrl());
     $clientRequest->setHeader('Date', $gmt_date);
     $clientRequest->setHeader('Content-Type', static::CONTENT_TYPE);
     $clientRequest->setHeader('Content-MD5', $content_md5);
     $clientRequest->setHeader('Authorization', $sign);
     $clientRequest->setUrl('http://' . $apiClient->getQueueOwnerId() . "." . $apiClient->getMqsUrl() . $clientRequest->getUrl());
     return $clientRequest;
 }
 public function prepare(ClientRequest $clientRequest)
 {
     $this->renew();
     $this->setUrl($clientRequest->getUrl());
     $this->setData($clientRequest->getContent());
     $this->setHeaders($clientRequest->getHeaders());
     $this->setMethod($clientRequest->getVerb());
     return $this;
 }