Skip to content

Commit 0831487

Browse files
committed
Added parse http host
1 parent 8e24106 commit 0831487

2 files changed

Lines changed: 13 additions & 0 deletions

File tree

src/GlobalState.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@ public static function enrichServerVars(Request $request): array
3535
$server['REQUEST_METHOD'] = $request->method;
3636
$server['HTTP_USER_AGENT'] = '';
3737

38+
$host = parse_url($request->uri, PHP_URL_HOST);
39+
$port = parse_url($request->uri, PHP_URL_PORT);
40+
41+
if ($host != null) {
42+
$server['HTTP_HOST'] = $host;
43+
}
44+
45+
if ($host != null && $port != null) {
46+
$server['HTTP_HOST'] = $host . ':' . $port;
47+
}
48+
3849
foreach ($request->headers as $key => $value) {
3950
$key = \strtoupper(\str_replace('-', '_', $key));
4051

tests/Unit/PSR7WorkerTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public function testStateServerLeak(): void
4444
'HTTP_USER_AGENT' => '',
4545
'CONTENT_TYPE' => 'application/html',
4646
'HTTP_CONNECTION' => 'keep-alive',
47+
'HTTP_HOST' => 'localhost',
4748
],
4849
],
4950
[
@@ -56,6 +57,7 @@ public function testStateServerLeak(): void
5657
'REQUEST_METHOD' => 'GET',
5758
'HTTP_USER_AGENT' => '',
5859
'CONTENT_TYPE' => 'application/json',
60+
'HTTP_HOST' => 'localhost',
5961
],
6062
],
6163
];

0 commit comments

Comments
 (0)