aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--application/HttpUtils.php14
-rw-r--r--tests/HttpUtils/ServerUrlTest.php28
2 files changed, 41 insertions, 1 deletions
diff --git a/application/HttpUtils.php b/application/HttpUtils.php
index a81f9056..88a1efdb 100644
--- a/application/HttpUtils.php
+++ b/application/HttpUtils.php
@@ -311,7 +311,19 @@ function server_url($server)
311 } 311 }
312 } 312 }
313 313
314 return $scheme.'://'.$server['SERVER_NAME'].$port; 314 if (isset($server['HTTP_X_FORWARDED_HOST'])) {
315 // Keep forwarded host
316 if (strpos($server['HTTP_X_FORWARDED_HOST'], ',') !== false) {
317 $hosts = explode(',', $server['HTTP_X_FORWARDED_HOST']);
318 $host = trim($hosts[0]);
319 } else {
320 $host = $server['HTTP_X_FORWARDED_HOST'];
321 }
322 } else {
323 $host = $server['SERVER_NAME'];
324 }
325
326 return $scheme.'://'.$host.$port;
315 } 327 }
316 328
317 // SSL detection 329 // SSL detection
diff --git a/tests/HttpUtils/ServerUrlTest.php b/tests/HttpUtils/ServerUrlTest.php
index 7fdad659..dac02b3e 100644
--- a/tests/HttpUtils/ServerUrlTest.php
+++ b/tests/HttpUtils/ServerUrlTest.php
@@ -39,6 +39,34 @@ class ServerUrlTest extends PHPUnit_Framework_TestCase
39 } 39 }
40 40
41 /** 41 /**
42 * Detect a Proxy that sets Forwarded-Host
43 */
44 public function testHttpsProxyForwardedHost()
45 {
46 $this->assertEquals(
47 'https://host.tld:8080',
48 server_url(
49 array(
50 'HTTP_X_FORWARDED_PROTO' => 'https',
51 'HTTP_X_FORWARDED_PORT' => '8080',
52 'HTTP_X_FORWARDED_HOST' => 'host.tld'
53 )
54 )
55 );
56
57 $this->assertEquals(
58 'https://host.tld:4974',
59 server_url(
60 array(
61 'HTTP_X_FORWARDED_PROTO' => 'https, https',
62 'HTTP_X_FORWARDED_PORT' => '4974, 80',
63 'HTTP_X_FORWARDED_HOST' => 'host.tld, example.com'
64 )
65 )
66 );
67 }
68
69 /**
42 * Detect a Proxy with SSL enabled 70 * Detect a Proxy with SSL enabled
43 */ 71 */
44 public function testHttpsProxyForward() 72 public function testHttpsProxyForward()