8000 bug #35553 Fix HTTP client config handling (julienfalque) · symfony/symfony@3750988 · GitHub
[go: up one dir, main page]

Skip to content

Commit 3750988

Browse files
committed
bug #35553 Fix HTTP client config handling (julienfalque)
This PR was merged into the 4.4 branch. Discussion ---------- Fix HTTP client config handling | Q | A | ------------- | --- | Branch? | 4.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Defining a `key` parameter in the `query` option of a scoped HTTP client triggers an error: ``` Undefined index: value ``` This PR fixes this issue but an edge case still remains with YAML and PHP config. If one wants to define parameters `key=foo`, `value=bar` and nothing else, the query will actually be `foo=bar` instead of `key=foo&value=bar`. Not sure how to fix this case without breaking the tests I added here. Commits ------- 963d0cc Fix HTTP client config handling
2 parents eaec5d6 + 963d0cc commit 3750988

File tree

5 files changed

+71
-3
lines changed

5 files changed

+71
-3
lines changed

src/Symfony/Bundle/FrameworkBundle/DependencyInjection/Configuration.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1402,7 +1402,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode)
14021402
if (!\is_array($config)) {
14031403
return [];
14041404
}
1405-
if (!isset($config['host'])) {
1405+
if (!isset($config['host'], $config['value']) || \count($config) > 2) {
14061406
return $config;
14071407
}
14081408

@@ -1511,7 +1511,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode)
15111511
if (!\is_array($config)) {
15121512
return [];
15131513
}
1514-
if (!isset($config['key'])) {
1514+
if (!isset($config['key'], $config['value']) || \count($config) > 2) {
15151515
return $config;
15161516
}
15171517

@@ -1541,7 +1541,7 @@ private function addHttpClientSection(ArrayNodeDefinition $rootNode)
15411541
if (!\is_array($config)) {
15421542
return [];
15431543
}
1544-
if (!isset($config['host'])) {
1544+
if (!isset($config['host'], $config['value']) || \count($config) > 2) {
15451545
return $config;
15461546
}
15471547

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
$container->loadFromExtension('framework', [
4+
'http_client' => [
5+
'default_options' => [
6+
'resolve' => [
7+
'host' => '127.0.0.1',
8+
],
9+
],
10+
'scoped_clients' => [
11+
'foo' => [
12+
'base_uri' => 'http://example.com',
13+
'query' => [
14+
'key' => 'foo',
15+
],
16+
'resolve' => [
17+
'host' => '127.0.0.1',
18+
],
19+
],
20+
],
21+
],
22+
]);
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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:default-options>
11+
<framework:resolve host="host">127.0.0.1</framework:resolve>
12+
</framework:default-options>
13+
<framework:scoped-client name="foo" base-uri="http://example.com">
14+
<framework:query key="key">foo</framework:query>
15+
<framework:resolve host="host">127.0.0.1</framework:resolve>
16+
</framework:scoped-client>
17+
</framework:http-client>
18+
</framework:config>
19+
</container>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
framework:
2+
http_client:
3+
default_options:
4+
resolve:
5+
host: 127.0.0.1
6+
scoped_clients:
7+
foo:
8+
base_uri: http://example.com
9+
query:
10+
key: foo
11+
resolve:
12+
host: 127.0.0.1

src/Symfony/Bundle/FrameworkBundle/Tests/DependencyInjection/FrameworkExtensionTest.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,6 +1559,21 @@ public function testHttpClientOverrideDefaultOptions()
15591559
$this->assertSame($expected, $container->getDefinition('foo')->getArgument(2));
15601560
}
15611561

1562+
public function testHttpClientWithQueryParameterKey()
1563+
{
1564+
$container = $this->createContainerFromFile('http_client_xml_key');
1565+
1566+
$expected = [
1567+
'key' => 'foo',
1568+
];
1569+
$this->assertSame($expected, $container->getDefinition('foo')->getArgument(2)['query']);
1570+
1571+
$expected = [
1572+
'host' => '127.0.0.1',
1573+
];
1574+
$this->assertSame($expected, $container->getDefinition('foo')->getArgument(2)['resolve']);
1575+
}
1576+
15621577
public function testHttpClientFullDefaultOptions()
15631578
{
15641579
$container = $this->createContainerFromFile('http_client_full_default_options');

0 commit comments

Comments
 (0)
0