]> git.immae.eu Git - github/shaarli/Shaarli.git/commitdiff
Hide default port in local URL behind a reverse proxy 733/head
authorArthurHoaro <arthur@hoa.ro>
Tue, 3 Jan 2017 13:17:05 +0000 (14:17 +0100)
committerArthurHoaro <arthur@hoa.ro>
Tue, 3 Jan 2017 13:17:05 +0000 (14:17 +0100)
application/HttpUtils.php
tests/HttpUtils/ServerUrlTest.php

index e705cfd6030cb0da7ff5e90bde930433bcecbbe0..e8fc1f5db45fc4ca11da2793068c373013339614 100644 (file)
@@ -297,9 +297,17 @@ function server_url($server)
             // Keep forwarded port
             if (strpos($server['HTTP_X_FORWARDED_PORT'], ',') !== false) {
                 $ports = explode(',', $server['HTTP_X_FORWARDED_PORT']);
-                $port = ':' . trim($ports[0]);
+                $port = trim($ports[0]);
             } 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 = '';
             }
         }
 
index 8a55a2202be11910e9dcb22c38f60554820efbc3..7fdad6594961e5995d40f050fc3f90fbeded7f3d 100644 (file)
@@ -68,6 +68,19 @@ class ServerUrlTest extends PHPUnit_Framework_TestCase
             )
         );
 
+        $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(
             'https://host.tld:4974',
             server_url(