[HttpClient] fix adding query string to relative URLs with scoped clients
This commit is contained in:
parent
90666777c7
commit
5ccba2c3e5
@ -71,11 +71,12 @@ class ScopingHttpClient implements HttpClientInterface, ResetInterface
|
||||
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) {
|
||||
|
@ -30,9 +30,9 @@ class ScopingHttpClientTest extends TestCase
|
||||
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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
Reference in New Issue
Block a user