diff --git a/src/Bridge/Symfony/Bundle/Test/Client.php b/src/Bridge/Symfony/Bundle/Test/Client.php index cc73bfb15bc..690bba2d195 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,23 @@ public function enableReboot(): void { $this->kernelBrowser->enableReboot(); } + + /** + * Normalize headers depending on the symfony/http-client version being used. + */ + 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; + } + }