Skip to content

Commit

Permalink
Navigation: The HTTP Host: header always implies a port.
Browse files Browse the repository at this point in the history
So don't tack on `SERVER_PORT` if `HTTP_HOST` was given.
  • Loading branch information
kohler committed Feb 15, 2024
1 parent 06d7363 commit 62abc45
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/navigation.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ static function make_server($server) {
$nav = new NavigationState;

// host, protocol, server
$nav->host = $server["HTTP_HOST"] ?? $server["SERVER_NAME"] ?? null;
$http_host = $server["HTTP_HOST"] ?? null;
$nav->host = $http_host ?? $server["SERVER_NAME"] ?? null;
if ((isset($server["HTTPS"])
&& $server["HTTPS"] !== ""
&& $server["HTTPS"] !== "off")
Expand All @@ -64,9 +65,10 @@ static function make_server($server) {
}
$nav->protocol = $x;
$x .= $nav->host ? : "localhost";
if (($port = $server["SERVER_PORT"])
&& $port != $xport
&& strpos($x, ":", 6) === false) {
if ($http_host === null // HTTP `Host` header should contain port
&& strpos($x, ":", 6) === false
&& ($port = $server["SERVER_PORT"])
&& $port != $xport) {
$x .= ":" . $port;
}
$nav->server = $x;
Expand Down

0 comments on commit 62abc45

Please sign in to comment.