Skip to content

Commit 30b901a

Browse files
[HttpClient] fix adding query string to relative URLs with scoped clients
1 parent 7bac9c0 commit 30b901a

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

ScopingHttpClient.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,12 @@ public function request(string $method, string $url, array $options = []): Respo
7171
throw $e;
7272
}
7373

74-
$options = self::mergeDefaultOptions($options, $this->defaultOptionsByRegexp[$this->defaultRegexp], true);
74+
$defaultOptions = $this->defaultOptionsByRegexp[$this->defaultRegexp];
75+
$options = self::mergeDefaultOptions($options, $defaultOptions, true);
7576
if (\is_string($options['base_uri'] ?? null)) {
7677
$options['base_uri'] = self::parseUrl($options['base_uri']);
7778
}
78-
$url = implode('', self::resolveUrl($url, $options['base_uri'] ?? null));
79+
$url = implode('', self::resolveUrl($url, $options['base_uri'] ?? null, $defaultOptions['query'] ?? []));
7980
}
8081

8182
foreach ($this->defaultOptionsByRegexp as $regexp => $defaultOptions) {

Tests/ScopingHttpClientTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ public function testRelativeUrl()
3030
public function testRelativeUrlWithDefaultRegexp()
3131
{
3232
$mockClient = new MockHttpClient();
33-
$client = new ScopingHttpClient($mockClient, ['.*' => ['base_uri' => 'http://example.com']], '.*');
33+
$client = new ScopingHttpClient($mockClient, ['.*' => ['base_uri' => 'http://example.com', 'query' => ['a' => 'b']]], '.*');
3434

35-
$this->assertSame('http://example.com/foo', $client->request('GET', '/foo')->getInfo('url'));
35+
$this->assertSame('http://example.com/foo?f=g&a=b', $client->request('GET', '/foo?f=g')->getInfo('url'));
3636
}
3737

3838
/**

0 commit comments

Comments
 (0)