/** * Sets options on a cURL resource based on a request. */ private static function setOptionsFromRequest($curl, RequestInterface $request) { $options = array(CURLOPT_HTTP_VERSION => $request->getProtocolVersion() == 1.0 ? CURL_HTTP_VERSION_1_0 : CURL_HTTP_VERSION_1_1, CURLOPT_CUSTOMREQUEST => $request->getMethod(), CURLOPT_URL => $request->getHost() . $request->getResource(), CURLOPT_HTTPHEADER => $request->getHeaders()); switch ($request->getMethod()) { case RequestInterface::METHOD_HEAD: $options[CURLOPT_NOBODY] = true; break; case RequestInterface::METHOD_GET: $options[CURLOPT_HTTPGET] = true; break; case RequestInterface::METHOD_POST: case RequestInterface::METHOD_PUT: case RequestInterface::METHOD_DELETE: case RequestInterface::METHOD_PATCH: case RequestInterface::METHOD_OPTIONS: $options[CURLOPT_POSTFIELDS] = $fields = static::getPostFields($request); // remove the content-type header if (is_array($fields)) { $options[CURLOPT_HTTPHEADER] = array_filter($options[CURLOPT_HTTPHEADER], function ($header) { return 0 !== stripos($header, 'Content-Type: '); }); } break; } curl_setopt_array($curl, $options); }
/** * Converts a request into an array for stream_context_create(). * * @param RequestInterface $request A request object * * @return array An array for stream_context_create() */ public function getStreamContextArray(RequestInterface $request) { $options = 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()), 'ssl' => array('verify_peer' => $this->getVerifyPeer())); if ($this->proxy) { $options['http']['proxy'] = $this->proxy; $options['http']['request_fulluri'] = true; } return $options; }
/** * Converts a request into an array for stream_context_create(). * * @param RequestInterface $request A request object * * @return array An array for stream_context_create() */ public function getStreamContextArray(RequestInterface $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()), 'ssl' => array('verify_peer' => $this->getVerifyPeer())); }