Skip to content

Commit 2d91c88

Browse files
authored
Merge pull request #8 from tarampampam/master
Fix the headers mapping
2 parents 5ad9b26 + 061b263 commit 2d91c88

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

src/HttpWorker.php

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,27 @@ private function hydrateRequest(Request $request, array $context): void
124124
\parse_str($context['rawQuery'], $request->query);
125125

126126
$request->attributes = (array)($context['attributes'] ?? []);
127-
$request->headers = (array)($context['headers'] ?? []);
127+
$request->headers = $this->filterHeaders((array)($context['headers'] ?? []));
128128
$request->cookies = (array)($context['cookies'] ?? []);
129129
$request->uploads = (array)($context['uploads'] ?? []);
130130
$request->parsed = (bool)$context['parsed'];
131131
}
132+
133+
/**
134+
* @param array<mixed, mixed> $headers
135+
*
136+
* @return array<string, mixed>
137+
*/
138+
private function filterHeaders(array $headers): array
139+
{
140+
foreach ($headers as $key => $_) {
141+
if (!\is_string($key) || $key === '') {
142+
// ignore invalid header names or values (otherwise, the worker will be crashed)
143+
// @see: <https://git.io/JzjgJ>
144+
unset($headers[$key]);
145+
}
146+
}
147+
148+
return $headers;
149+
}
132150
}

0 commit comments

Comments
 (0)