options = $options === null ? new RequestOptions() : clone $options; } /** * @param string $method HTTP method * @param string|UriInterface $uri URI * @param array $headers Request headers * @param string|null|resource|StreamInterface $body Request body * @param string $version Protocol version * * @throws TransferErrorExceptionInterface * * @return ServerResponseInterface */ public function request($method, $uri, array $headers = [], $body = null, $version = '1.1'): ServerResponseInterface { $request = new ClientRequest($method, $uri, $headers, $body, $version); return $this->sendRequest($request); } /** * @param ClientRequestInterface $request * @param RequestOptions|null $options * * @throws TransferErrorExceptionInterface * * @return ServerResponseInterface */ public function sendRequest( ClientRequestInterface $request, RequestOptions $options = null ): ServerResponseInterface { $optionsArray = $options === null ? $this->options->toArray() : $options->toArray(); try { $client = $this->createClient(); $response = $client->send($request, $optionsArray); return ServerResponse::fromGuzzleResponse($response); // } catch (GuzzleException $exception) { throw TransferErrorException::fromGuzzleException($exception); } } /** * @return GuzzleClient */ private function createClient(): GuzzleClient { return new GuzzleClient($this->options->toArray()); } }