예제 #1
0
 protected static function setCurlOptsFromRequest($curl, Message\Request $request)
 {
     curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->getMethod());
     curl_setopt($curl, CURLOPT_URL, $request->getUrl());
     curl_setopt($curl, CURLOPT_HTTPHEADER, $request->getHeaders());
     curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getContent());
 }
예제 #2
0
 public function getHeaders()
 {
     $headers = parent::getHeaders();
     if ($this->isSafe()) {
         return $headers;
     }
     if ($this->isMultipart()) {
         $headers[] = 'Content-Type: multipart/form-data; boundary=' . $this->getBoundary();
     } else {
         $headers[] = 'Content-Type: application/x-www-form-urlencoded';
     }
     return $headers;
 }
예제 #3
0
파일: Curl.php 프로젝트: kingsj/core
 protected static function setCurlOptsFromRequest($curl, Message\Request $request)
 {
     $options = array(CURLOPT_CUSTOMREQUEST => $request->getMethod(), CURLOPT_URL => $request->getUrl(), CURLOPT_HTTPHEADER => $request->getHeaders(), CURLOPT_HTTPGET => false, CURLOPT_NOBODY => false, CURLOPT_POSTFIELDS => null);
     switch ($request->getMethod()) {
         case Message\Request::METHOD_HEAD:
             $options[CURLOPT_NOBODY] = true;
             break;
         case Message\Request::METHOD_GET:
             $options[CURLOPT_HTTPGET] = true;
             break;
         case Message\Request::METHOD_POST:
         case Message\Request::METHOD_PUT:
             $options[CURLOPT_POSTFIELDS] = $fields = self::getPostFields($request);
             // remove the content-type header
             if (is_array($fields)) {
                 $options[CURLOPT_HTTPHEADER] = array_filter($options[CURLOPT_HTTPHEADER], function ($header) {
                     return 0 !== strpos($header, 'Content-Type: ');
                 });
             }
             break;
     }
     curl_setopt_array($curl, $options);
 }
예제 #4
0
 /**
  * Removes the CSRF token header from a $request.
  *
  * @param Request $request
  */
 private function removeCsrfHeader(Request $request)
 {
     foreach ($request->getHeaders() as $headerString) {
         list($headerName) = explode(': ', $headerString);
         if (strtolower($headerName) !== 'x-csrf-token') {
             $headers[] = $headerString;
         }
     }
     $request->setHeaders($headers);
 }
예제 #5
0
 public function testCookieMerge()
 {
     $request = new Request();
     $request->addHeader('Cookie: foo=bar');
     $request->addHeader('Content-Type: text/plain');
     $request->addHeader('Cookie: bar=foo');
     $this->assertEquals(array('Cookie: foo=bar; bar=foo', 'Content-Type: text/plain'), $request->getHeaders());
     $expected = "GET / HTTP/1.0\r\n";
     $expected .= "Cookie: foo=bar; bar=foo\r\n";
     $expected .= "Content-Type: text/plain\r\n";
     $this->assertEquals($expected, (string) $request);
 }
 /**
  * Converts a request into an array for stream_context_create().
  * 
  * @param Message\Request $request A request object
  * 
  * @return array An array for stream_context_create()
  */
 public function getStreamContextArray(Message\Request $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()));
 }