Ejemplo n.º 1
0
 /**
  * @param Request $request
  *
  * @return resource
  */
 protected function buildCurlResource(Request $request)
 {
     $ch = curl_init((string) $request->getUrl());
     $options = $this->curlOptions;
     $options[CURLOPT_CUSTOMREQUEST] = $request->getMethod();
     // configuring a POST request
     if ($request->isPost() && $request->getPost()) {
         $options[CURLOPT_POSTFIELDS] = $request->getPost();
     }
     if ($request->isHead()) {
         $options[CURLOPT_NOBODY] = TRUE;
     } else {
         if ($request->isGet()) {
             $options[CURLOPT_HTTPGET] = TRUE;
         }
     }
     // disable the 'Expect: 100-continue' behaviour. This causes CURL to wait
     // for 2 seconds if the server does not support this header.
     $options[CURLOPT_HTTPHEADER]['Expect'] = '';
     $tmp = [];
     foreach ($request->getHeaders() + $options[CURLOPT_HTTPHEADER] as $name => $value) {
         $tmp[] = trim("{$name}: {$value}");
     }
     $options[CURLOPT_HTTPHEADER] = $tmp;
     // execute request
     curl_setopt_array($ch, $options);
     $this->onRequest($request, $options);
     return $ch;
 }
Ejemplo n.º 2
0
 /**
  * @param Api\Request $request
  * @param array $options
  */
 public function begin(Api\Request $request, $options = array())
 {
     $url = $request->getUrl();
     $url->setQuery('');
     $this->calls[spl_object_hash($request)] = (object) array('url' => (string) $url, 'params' => $request->getParameters(), 'options' => self::toConstantNames($options), 'result' => NULL, 'exception' => NULL, 'info' => array(), 'time' => 0);
 }