Skip to content

Commit

Permalink
Apply on request the version set in options parameters
Browse files Browse the repository at this point in the history
Co-Authored-By: Mponos George <5675248+gmponos@users.noreply.github.com>
  • Loading branch information
GrahamCampbell and gmponos committed May 14, 2023
1 parent 3d12c4b commit 3380b7d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Client.php
Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions tests/ClientTest.php
Expand Up @@ -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);
Expand Down

0 comments on commit 3380b7d

Please sign in to comment.