/** * {@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()); }