From b943084c955a3e2a26af330488d873daeff72c43 Mon Sep 17 00:00:00 2001 From: Beno!t POLASZEK Date: Wed, 4 Sep 2019 16:41:21 +0200 Subject: [PATCH] Fix #3038 --- src/Bridge/Symfony/Bundle/Test/Client.php | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/Bridge/Symfony/Bundle/Test/Client.php b/src/Bridge/Symfony/Bundle/Test/Client.php index cc73bfb15bc..30ed955f547 100644 --- a/src/Bridge/Symfony/Bundle/Test/Client.php +++ b/src/Bridge/Symfony/Bundle/Test/Client.php @@ -92,7 +92,7 @@ public function request(string $method, string $url, array $options = []): Respo $server = []; // Convert headers to a $_SERVER-like array - foreach ($options['headers'] as $key => $value) { + foreach (self::extractHeaders($options) as $key => $value) { if ('content-type' === $key) { $server['CONTENT_TYPE'] = $value[0] ?? ''; @@ -212,4 +212,24 @@ public function enableReboot(): void { $this->kernelBrowser->enableReboot(); } + + /** + * Normalize headers depending on the symfony/http-client version being used. + * + * @return array + */ + private static function extractHeaders(array $options): array + { + $headers = $options['normalized_headers'] ?? $options['headers']; + foreach ($headers as $key => &$values) { + foreach ($values as &$value) { + $prefix = $key.':'; + if (0 === stripos($value, $prefix)) { + $value = ltrim(substr($value, \strlen($prefix))); + } + } + } + + return $headers; + } }