Skip to content

Commit 3b0c6f9

Browse files
bug symfony#41224 [HttpClient] fix adding query string to relative URLs with scoped clients (nicolas-grekas)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpClient] fix adding query string to relative URLs with scoped clients | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | Fix symfony#41220 | License | MIT | Doc PR | - Commits ------- 5ccba2c [HttpClient] fix adding query string to relative URLs with scoped clients
2 parents 9e12a38 + 5ccba2c commit 3b0c6f9

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
lines changed

src/Symfony/Component/HttpClient/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) {

src/Symfony/Component/HttpClient/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)