diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index af1bfa0..1290304 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -83,6 +83,7 @@ private function createClientsNode() // @todo @deprecated ->arrayNode('headers') + ->normalizeKeys(false) ->prototype('scalar') ->end() ->end() @@ -90,6 +91,7 @@ private function createClientsNode() ->arrayNode('options') ->children() ->arrayNode('headers') + ->normalizeKeys(false) ->prototype('scalar') ->end() ->end() diff --git a/DependencyInjection/GuzzleExtension.php b/DependencyInjection/GuzzleExtension.php index 66a07f4..17aff21 100644 --- a/DependencyInjection/GuzzleExtension.php +++ b/DependencyInjection/GuzzleExtension.php @@ -53,12 +53,6 @@ public function load(array $configs, ContainerBuilder $container) 'handler' => $this->createHandler($container, $name, $options) ]; - // header hotfix/workaround #77 - // @todo @deprecated - if (isset($options['headers'])) { - $argument['headers'] = $this->cleanUpHeaders($options['headers']); - } - // if present, add default options to the constructor argument for the Guzzle client if (array_key_exists('options', $options) && is_array($options['options'])) { @@ -68,12 +62,6 @@ public function load(array $configs, ContainerBuilder $container) continue; } - // @todo: cleanup - if ($key === 'headers') { - $argument[$key] = $this->cleanUpHeaders($value); - continue; - } - $argument[$key] = $value; } } @@ -235,31 +223,6 @@ protected function createWsseMiddleware($username, $password, $createdAtExpressi return $wsse; } - /** - * Clean up HTTP headers - * - * @since 2015-07 - * - * @param array $headers - * - * @return array - */ - protected function cleanUpHeaders(array $headers) - { - foreach ($headers as $name => $value) { - - // because of standard conventions in YAML dashes are converted to underscores - // underscores are not allowed in HTTP standard, will be replaced by dash - $nameClean = str_replace('_', '-', $name); - - unset($headers[$name]); - - $headers[$nameClean] = $value; - } - - return $headers; - } - /** * Returns alias of extension * diff --git a/Tests/DependencyInjection/ConfigurationTest.php b/Tests/DependencyInjection/ConfigurationTest.php index b028a5d..0f8b834 100644 --- a/Tests/DependencyInjection/ConfigurationTest.php +++ b/Tests/DependencyInjection/ConfigurationTest.php @@ -196,4 +196,38 @@ public function testSingleClientConfigWithProxyAsString() 'clients' => ['test_client' => ['options' => ['proxy' => ['http' => 'http://proxy.org']]]] ]), $processedConfig); } + + public function testHeaderWithUnderscore() + { + $config = [ + 'guzzle' => [ + 'clients' => [ + 'test_client' => [ + 'headers' => [ + 'Header_underscored' => 'some-random-hash', + 'Header-hyphened' => 'another-random-hash' + ], + 'options' => [ + 'headers' => [ + 'Header_underscored' => 'some-random-hash', + 'Header-hyphened' => 'another-random-hash' + ], + ] + ] + ] + ] + ]; + + $processor = new Processor(); + $processedConfig = $processor->processConfiguration(new Configuration(true), $config); + + $headers = $processedConfig['clients']['test_client']['headers']; + $optionsHeaders = $processedConfig['clients']['test_client']['options']['headers']; + + foreach ([$headers, $optionsHeaders] as $headerConfig) + { + $this->assertArrayHasKey('Header_underscored', $headerConfig); + $this->assertArrayHasKey('Header-hyphened', $headerConfig); + } + } }