Skip to content

Commit 71f8a40

Browse files
committed
fix: for parse host and port
1 parent a2b779c commit 71f8a40

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/Server/Request.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,17 @@ private static function getUriFromGlobals(\Swoole\Http\Request $swooleRequest)
180180
} elseif (isset($server['server_addr'])) {
181181
$uri = $uri->withHost($server['server_addr']);
182182
} elseif (isset($header['host'])) {
183-
$host = \strpos($header['host'], ':') ? explode(':', $header['host'])[0] : $header['host'];
183+
if (\strpos($header['host'], ':')) {
184+
$hasPort = true;
185+
list($host, $port) = explode(':', $header['host'], 2);
186+
187+
if ($port !== '80') {
188+
$uri = $uri->withPort($port);
189+
}
190+
} else {
191+
$host = $header['host'];
192+
}
193+
184194
$uri = $uri->withHost($host);
185195
}
186196

0 commit comments

Comments
 (0)