Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
bug #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 #41220
| License       | MIT
| Doc PR        | -

Commits
-------

5ccba2c [HttpClient] fix adding query string to relative URLs with scoped clients
  • Loading branch information
nicolas-grekas committed May 15, 2021
2 parents 9e12a38 + 5ccba2c commit 3b0c6f9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/Symfony/Component/HttpClient/ScopingHttpClient.php
Expand Up @@ -71,11 +71,12 @@ public function request(string $method, string $url, array $options = []): Respo
throw $e;
}

$options = self::mergeDefaultOptions($options, $this->defaultOptionsByRegexp[$this->defaultRegexp], true);
$defaultOptions = $this->defaultOptionsByRegexp[$this->defaultRegexp];
$options = self::mergeDefaultOptions($options, $defaultOptions, true);
if (\is_string($options['base_uri'] ?? null)) {
$options['base_uri'] = self::parseUrl($options['base_uri']);
}
$url = implode('', self::resolveUrl($url, $options['base_uri'] ?? null));
$url = implode('', self::resolveUrl($url, $options['base_uri'] ?? null, $defaultOptions['query'] ?? []));
}

foreach ($this->defaultOptionsByRegexp as $regexp => $defaultOptions) {
Expand Down
Expand Up @@ -30,9 +30,9 @@ public function testRelativeUrl()
public function testRelativeUrlWithDefaultRegexp()
{
$mockClient = new MockHttpClient();
$client = new ScopingHttpClient($mockClient, ['.*' => ['base_uri' => 'http://example.com']], '.*');
$client = new ScopingHttpClient($mockClient, ['.*' => ['base_uri' => 'http://example.com', 'query' => ['a' => 'b']]], '.*');

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

/**
Expand Down

0 comments on commit 3b0c6f9

Please sign in to comment.