Merge pull request #733 from ArthurHoaro/hotfix/reverse-proxy-port
Hide default ports in local URL behind a reverse proxy
This commit is contained in:
commit
061f04fba0
2 changed files with 23 additions and 2 deletions
|
@ -297,9 +297,17 @@ function server_url($server)
|
||||||
// Keep forwarded port
|
// Keep forwarded port
|
||||||
if (strpos($server['HTTP_X_FORWARDED_PORT'], ',') !== false) {
|
if (strpos($server['HTTP_X_FORWARDED_PORT'], ',') !== false) {
|
||||||
$ports = explode(',', $server['HTTP_X_FORWARDED_PORT']);
|
$ports = explode(',', $server['HTTP_X_FORWARDED_PORT']);
|
||||||
$port = ':' . trim($ports[0]);
|
$port = trim($ports[0]);
|
||||||
} else {
|
} else {
|
||||||
$port = ':' . $server['HTTP_X_FORWARDED_PORT'];
|
$port = $server['HTTP_X_FORWARDED_PORT'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (($scheme == 'http' && $port != '80')
|
||||||
|
|| ($scheme == 'https' && $port != '443')
|
||||||
|
) {
|
||||||
|
$port = ':' . $port;
|
||||||
|
} else {
|
||||||
|
$port = '';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -68,6 +68,19 @@ public function testHttpsProxyForward()
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
$this->assertEquals(
|
||||||
|
'https://host.tld',
|
||||||
|
server_url(
|
||||||
|
array(
|
||||||
|
'HTTPS' => 'Off',
|
||||||
|
'SERVER_NAME' => 'host.tld',
|
||||||
|
'SERVER_PORT' => '80',
|
||||||
|
'HTTP_X_FORWARDED_PROTO' => 'https',
|
||||||
|
'HTTP_X_FORWARDED_PORT' => '443'
|
||||||
|
)
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
$this->assertEquals(
|
$this->assertEquals(
|
||||||
'https://host.tld:4974',
|
'https://host.tld:4974',
|
||||||
server_url(
|
server_url(
|
||||||
|
|
Loading…
Reference in a new issue