From 3380b7d81b535478c53a4f3b9a8f0dde0f3820cc Mon Sep 17 00:00:00 2001 From: Graham Campbell Date: Sun, 14 May 2023 12:13:34 +0200 Subject: [PATCH] Apply on request the version set in options parameters Co-Authored-By: Mponos George <5675248+gmponos@users.noreply.github.com> --- src/Client.php | 4 ++++ tests/ClientTest.php | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/Client.php b/src/Client.php index 58f1d891a..c21fcb6e4 100644 --- a/src/Client.php +++ b/src/Client.php @@ -437,6 +437,10 @@ private function applyOptions(RequestInterface $request, array &$options): Reque } } + if (isset($options['version'])) { + $modify['version'] = $options['version']; + } + $request = Psr7\Utils::modifyRequest($request, $modify); if ($request->getBody() instanceof Psr7\MultipartStream) { // Use a multipart/form-data POST if a Content-Type is not set. diff --git a/tests/ClientTest.php b/tests/ClientTest.php index 2a36623dc..e330679ed 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -708,6 +708,26 @@ public function testOnlyAddSchemeWhenHostIsPresent() ); } + public function testThatVersionIsOverwrittenWhenSendingARequest() + { + $mockHandler = new MockHandler([new Response(), new Response()]); + $client = new Client(['handler' => $mockHandler]); + + $request = new Request('get', '/bar', [], null, '1.1'); + $client->send($request, [RequestOptions::VERSION => '1.0']); + self::assertSame( + '1.0', + $mockHandler->getLastRequest()->getProtocolVersion() + ); + + $request = new Request('get', '/bar', [], null, '1.0'); + $client->send($request, [RequestOptions::VERSION => '1.1']); + self::assertSame( + '1.1', + $mockHandler->getLastRequest()->getProtocolVersion() + ); + } + public function testHandlerIsCallable() { $this->expectException(\InvalidArgumentException::class);