Skip to content

Commit

Permalink
Fix #3038
Browse files Browse the repository at this point in the history
Co-authored-by: Teoh Han Hui <teohhanhui@gmail.com>
  • Loading branch information
bcobzh and teohhanhui committed Sep 5, 2019
1 parent 4bf6c83 commit 2708733
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions src/Bridge/Symfony/Bundle/Test/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@ public function request(string $method, string $url, array $options = []): Respo
$basic = $options['auth_basic'] ?? null;
[$url, $options] = self::prepareRequest($method, $url, $options, $this->defaultOptions);
$resolvedUrl = implode('', $url);

$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] ?? '';

continue;
}

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

if ($basic) {
Expand Down Expand Up @@ -212,4 +212,28 @@ public function enableReboot(): void
{
$this->kernelBrowser->enableReboot();
}

/**
* Extracts headers depending on the symfony/http-client version being used.
*
* @return array<string, string[]>
*/
private static function extractHeaders(array $options): array
{
if (!isset($options['normalized_headers'])) {
return $options['headers'];
}

$headers = [];

/** @var string $key */
foreach ($options['normalized_headers'] as $key => $values) {
foreach ($values as $value) {
[, $value] = explode(': ', $value, 2);
$headers[$key][] = $value;
}
}

return $headers;
}
}

0 comments on commit 2708733

Please sign in to comment.