Skip to content

Commit 7522b55

Browse files
bug #36377 [HttpClient] Fix scoped client without query option configuration (X-Coder264)
This PR was merged into the 4.4 branch. Discussion ---------- [HttpClient] Fix scoped client without query option configuration | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | | License | MIT | Doc PR | The `query` key default value is an [empty array](https://github.com/symfony/symfony/blob/v4.4.7/src/Symfony/Component/Config/Definition/PrototypedArrayNode.php#L30) and because of that it is always set. Processing a configuration for a scoped HTTP client (which has a `scope` and does not have a `base_uri`) results in the configuration being invalid. The error message says that query parameters cannot be aplied to the base URI since it is not defined (which doesn't make sense since the query parameters don't exist because they are empty). Commits ------- a07578dba3 [HttpClient] Fix scoped client without query option configuration
2 parents 3ac7be8 + 318661e commit 7522b55

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

DependencyInjection/Configuration.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1482,7 +1482,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode)
14821482
->thenInvalid('Either "scope" or "base_uri" should be defined.')
14831483
->end()
14841484
->validate()
1485-
->ifTrue(function ($v) { return isset($v['query']) && !isset($v['base_uri']); })
1485+
->ifTrue(function ($v) { return !empty($v['query']) && !isset($v['base_uri']); })
14861486
->thenInvalid('"query" applies to "base_uri" but no base URI is defined.')
14871487
->end()
14881488
->children()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'http_client' => [
5+
'scoped_clients' => [
6+
'foo' => [
7+
'scope' => '.*',
8+
],
9+
],
10+
],
11+
]);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?xml version="1.0" encoding="utf-8" ?>
2+
<container xmlns="http://symfony.com/schema/dic/services"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xmlns:framework="http://symfony.com/schema/dic/symfony"
5+
xsi:schemaLocation="http://symfony.com/schema/dic/services http://symfony.com/schema/dic/services/services-1.0.xsd
6+
http://symfony.com/schema/dic/symfony http://symfony.com/schema/dic/symfony/symfony-1.0.xsd">
7+
8+
<framework:config>
9+
<framework:http-client>
10+
<framework:scoped-client
11+
name="foo"
12+
scope=".*"
13+
/>
14+
</framework:http-client>
15+
</framework:config>
16+
</container>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
framework:
2+
http_client:
3+
scoped_clients:
4+
foo:
5+
scope: '.*'

Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,6 +1547,14 @@ public function testHttpClientDefaultOptions()
15471547
$this->assertSame(ScopingHttpClient::class, $container->getDefinition('foo')->getClass());
15481548
}
15491549

1550+
public function testScopedHttpClientWithoutQueryOption()
1551+
{
1552+
$container = $this->createContainerFromFile('http_client_scoped_without_query_option');
1553+
1554+
$this->assertTrue($container->hasDefinition('foo'), 'should have the "foo" service.');
1555+
$this->assertSame(ScopingHttpClient::class, $container->getDefinition('foo')->getClass());
1556+
}
1557+
15501558
public function testHttpClientOverrideDefaultOptions()
15511559
{
15521560
$container = $this->createContainerFromFile('http_client_override_default_options');

0 commit comments

Comments
 (0)