Exemple #1
0
 /**
  * testThatSigningAuthHeadersOnPostRequestsWorks
  *
  * @return void
  */
 public function testThatSigningAuthHeadersOnPostRequestsWorks()
 {
     $request = new ClientHttp($this->consumer->http, $this->requestUri->path, array(), 'POST');
     $request->setFormData($this->requestParameters);
     $this->Token->sign($request, array('nonce' => $this->nonce, 'timestamp' => $this->timestamp));
     $this->assertEqual('POST', $request->method);
     $this->assertEqual('/test', $request->path);
     $this->assertEqual('key=value', $request->body());
     $this->assertEqual($this->toOrderedArray("OAuth oauth_nonce=\"225579211881198842005988698334675835446\", oauth_signature_method=\"HMAC-SHA1\", oauth_token=\"token_411a7f\", oauth_timestamp=\"1199645624\", oauth_consumer_key=\"consumer_key_86cad9\", oauth_signature=\"26g7wHTtNO6ZWJaLltcueppHYiI%3D\", oauth_version=\"1.0\""), $this->toOrderedArray($request->authorization));
 }
Exemple #2
0
 /**
  * Create the http request object for a given httpMethod and path
  *
  * @param HttpSocket $socket
  * @param string $httpMethod
  * @param string $path
  * @param array $params
  * @return ClientHttp, Request instanse
  */
 protected function _createHttpRequest(&$socket, $httpMethod, $path, $params = array())
 {
     if (isset($params['data'])) {
         $data = $params['data'];
         unset($params['data']);
     } else {
         $data = null;
     }
     if (isset($params['headers'])) {
         $headers = $params['headers'];
         unset($params['headers']);
     } else {
         $headers = $params;
     }
     switch (strtoupper($httpMethod)) {
         case 'POST':
             $request = new ClientHttp($socket, $path, $headers, 'POST');
             //$request->Request->registerCustomHeader('Content-Length: 0'); // Default to 0
             break;
         case 'PUT':
             $request = new ClientHttp($socket, $path, $headers, 'PUT');
             //$request->Request->registerCustomHeader('Content-Length: 0');
             break;
         case 'GET':
             $request = new ClientHttp($socket, $path, $headers, 'GET');
             break;
         case 'DELETE':
             $request = new ClientHttp($socket, $path, $headers, 'DELETE');
             break;
         case 'HEAD':
             $request = new ClientHttp($socket, $path, $headers, 'HEAD');
             break;
         default:
             throw new Exception("Don't know how to handle httpMethod: " . $httpMethod);
             break;
     }
     if (is_array($data)) {
         $request->setFormData($data);
     } elseif (!empty($data)) {
         $request->body($data);
         //$request->Request->registerCustomHeader('Content-Length: ' . strlen($data));
     }
     return $request;
 }