diff options
author | ArthurHoaro <arthur@hoa.ro> | 2017-01-03 14:17:05 +0100 |
---|---|---|
committer | ArthurHoaro <arthur@hoa.ro> | 2017-01-03 14:17:05 +0100 |
commit | 8e4be773685f7dff074f23e2df13072577091f44 (patch) | |
tree | 7d32c71008a03f44dc0f56990b1e2520fbb5c659 | |
parent | 436479c58f0da23fb05c3b26941beabd89d87561 (diff) | |
download | Shaarli-8e4be773685f7dff074f23e2df13072577091f44.tar.gz Shaarli-8e4be773685f7dff074f23e2df13072577091f44.tar.zst Shaarli-8e4be773685f7dff074f23e2df13072577091f44.zip |
Hide default port in local URL behind a reverse proxy
-rw-r--r-- | application/HttpUtils.php | 12 | ||||
-rw-r--r-- | tests/HttpUtils/ServerUrlTest.php | 13 |
2 files changed, 23 insertions, 2 deletions
diff --git a/application/HttpUtils.php b/application/HttpUtils.php index e705cfd6..e8fc1f5d 100644 --- a/application/HttpUtils.php +++ b/application/HttpUtils.php | |||
@@ -297,9 +297,17 @@ function server_url($server) | |||
297 | // Keep forwarded port | 297 | // Keep forwarded port |
298 | if (strpos($server['HTTP_X_FORWARDED_PORT'], ',') !== false) { | 298 | if (strpos($server['HTTP_X_FORWARDED_PORT'], ',') !== false) { |
299 | $ports = explode(',', $server['HTTP_X_FORWARDED_PORT']); | 299 | $ports = explode(',', $server['HTTP_X_FORWARDED_PORT']); |
300 | $port = ':' . trim($ports[0]); | 300 | $port = trim($ports[0]); |
301 | } else { | 301 | } else { |
302 | $port = ':' . $server['HTTP_X_FORWARDED_PORT']; | 302 | $port = $server['HTTP_X_FORWARDED_PORT']; |
303 | } | ||
304 | |||
305 | if (($scheme == 'http' && $port != '80') | ||
306 | || ($scheme == 'https' && $port != '443') | ||
307 | ) { | ||
308 | $port = ':' . $port; | ||
309 | } else { | ||
310 | $port = ''; | ||
303 | } | 311 | } |
304 | } | 312 | } |
305 | 313 | ||
diff --git a/tests/HttpUtils/ServerUrlTest.php b/tests/HttpUtils/ServerUrlTest.php index 8a55a220..7fdad659 100644 --- a/tests/HttpUtils/ServerUrlTest.php +++ b/tests/HttpUtils/ServerUrlTest.php | |||
@@ -69,6 +69,19 @@ class ServerUrlTest extends PHPUnit_Framework_TestCase | |||
69 | ); | 69 | ); |
70 | 70 | ||
71 | $this->assertEquals( | 71 | $this->assertEquals( |
72 | 'https://host.tld', | ||
73 | server_url( | ||
74 | array( | ||
75 | 'HTTPS' => 'Off', | ||
76 | 'SERVER_NAME' => 'host.tld', | ||
77 | 'SERVER_PORT' => '80', | ||
78 | 'HTTP_X_FORWARDED_PROTO' => 'https', | ||
79 | 'HTTP_X_FORWARDED_PORT' => '443' | ||
80 | ) | ||
81 | ) | ||
82 | ); | ||
83 | |||
84 | $this->assertEquals( | ||
72 | 'https://host.tld:4974', | 85 | 'https://host.tld:4974', |
73 | server_url( | 86 | server_url( |
74 | array( | 87 | array( |