Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply on request the version set in options parameters #3135

Merged
merged 1 commit into from May 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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