/** * {@inheritdoc} */ protected function sendInternalRequest(InternalRequestInterface $internalRequest) { $request = new Request(); foreach ($this->prepareHeaders($internalRequest) as $name => $value) { $request->header($name, $value); } $request->method($internalRequest->getMethod()); $request->body($this->prepareBody($internalRequest)); $request->url($uri = (string) $internalRequest->getUri()); $request->version($this->getConfiguration()->getProtocolVersion()); try { $response = $this->client->send($request, array('timeout' => $this->getConfiguration()->getTimeout(), 'redirect' => false)); } catch (\Exception $e) { throw HttpAdapterException::cannotFetchUri($uri, $this->getName(), $e->getMessage()); } return $this->getConfiguration()->getMessageFactory()->createResponse((int) $response->statusCode(), $response->version(), $response->headers(), $response->body()); }
/** * {@inheritdoc} */ public function sendRequest(RequestInterface $request) { $cakeRequest = new Request(); $cakeRequest->method($request->getMethod()); $cakeRequest->url((string) $request->getUri()); $cakeRequest->version($request->getProtocolVersion()); $cakeRequest->body($request->getBody()->getContents()); foreach ($request->getHeaders() as $header => $values) { $cakeRequest->header($header, $request->getHeaderLine($header)); } if (null === $cakeRequest->header('Content-Type')) { $cakeRequest->header('Content-Type', 'application/x-www-form-urlencoded'); } try { $cakeResponse = $this->client->send($cakeRequest, $this->client->config()); } catch (Exception $exception) { throw new NetworkException('Failed to send request', $request, $exception); } return $this->responseFactory->createResponse($cakeResponse->statusCode(), null, $cakeResponse->headers(), $cakeResponse->body(), $cakeResponse->version()); }
/** * Build miscellaneous options for the request. * * @param \Cake\Network\Http\Request $request The request being sent. * @param array $options Array of options to use. * @return void */ protected function _buildOptions(Request $request, $options) { $this->_contextOptions['method'] = $request->method(); $this->_contextOptions['protocol_version'] = $request->version(); $this->_contextOptions['ignore_errors'] = true; if (isset($options['timeout'])) { $this->_contextOptions['timeout'] = $options['timeout']; } if (isset($options['redirect'])) { $this->_contextOptions['max_redirects'] = (int) $options['redirect']; } }
/** * test version method. * * @return void */ public function testVersion() { $request = new Request(); $result = $request->version('1.0'); $this->assertSame($request, $request, 'Should return self'); $this->assertSame('1.0', $request->version()); }