Skip to content

Commit b0cd959

Browse files
bcobzhteohhanhui
andcommitted
Fix #3038
Co-authored-by: Teoh Han Hui <[email protected]>
1 parent 4bf6c83 commit b0cd959

File tree

1 file changed

+27
-3
lines changed

1 file changed

+27
-3
lines changed

src/Bridge/Symfony/Bundle/Test/Client.php

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,18 +89,18 @@ public function request(string $method, string $url, array $options = []): Respo
8989
$basic = $options['auth_basic'] ?? null;
9090
[$url, $options] = self::prepareRequest($method, $url, $options, $this->defaultOptions);
9191
$resolvedUrl = implode('', $url);
92-
9392
$server = [];
93+
9494
// Convert headers to a $_SERVER-like array
95-
foreach ($options['headers'] as $key => $value) {
95+
foreach (self::extractHeaders($options) as $key => $value) {
9696
if ('content-type' === $key) {
9797
$server['CONTENT_TYPE'] = $value[0] ?? '';
9898

9999
continue;
100100
}
101101

102102
// BrowserKit doesn't support setting several headers with the same name
103-
$server['HTTP_'.strtoupper(str_replace('-', '_', $key))] = $value[0] ?? '';
103+
$server['HTTP_'.strtoupper(strtr($key, '-', '_'))] = $value[0] ?? '';
104104
}
105105

106106
if ($basic) {
@@ -212,4 +212,28 @@ public function enableReboot(): void
212212
{
213213
$this->kernelBrowser->enableReboot();
214214
}
215+
216+
/**
217+
* Extracts headers depending on the symfony/http-client version being used.
218+
*
219+
* @return array<string, string[]>
220+
*/
221+
private static function extractHeaders(array $options): array
222+
{
223+
if (!isset($options['normalized_headers'])) {
224+
return $options['headers'];
225+
}
226+
227+
$headers = [];
228+
229+
/** @var string $key */
230+
foreach ($options['normalized_headers'] as $key => $values) {
231+
foreach ($values as $value) {
232+
[, $value] = explode(': ', $value, 2);
233+
$headers[$key][] = $value;
234+
}
235+
}
236+
237+
return $headers;
238+
}
215239
}

0 commit comments

Comments
 (0)