Merge pull request #505 from ArthurHoaro/hotfix/multi-reverse-proxy

Fixes #477: support multi reverse proxy with comma syntax
This commit is contained in:
Arthur 2016-03-01 12:15:10 +01:00
commit 6e7a3210c3
2 changed files with 25 additions and 2 deletions

View file

@ -106,11 +106,21 @@ function server_url($server)
// Shaarli is served behind a proxy // Shaarli is served behind a proxy
if (isset($server['HTTP_X_FORWARDED_PROTO'])) { if (isset($server['HTTP_X_FORWARDED_PROTO'])) {
// Keep forwarded scheme // Keep forwarded scheme
$scheme = $server['HTTP_X_FORWARDED_PROTO']; if (strpos($server['HTTP_X_FORWARDED_PROTO'], ',') !== false) {
$schemes = explode(',', $server['HTTP_X_FORWARDED_PROTO']);
$scheme = trim($schemes[0]);
} else {
$scheme = $server['HTTP_X_FORWARDED_PROTO'];
}
if (isset($server['HTTP_X_FORWARDED_PORT'])) { if (isset($server['HTTP_X_FORWARDED_PORT'])) {
// Keep forwarded port // Keep forwarded port
$port = ':'.$server['HTTP_X_FORWARDED_PORT']; if (strpos($server['HTTP_X_FORWARDED_PORT'], ',') !== false) {
$ports = explode(',', $server['HTTP_X_FORWARDED_PORT']);
$port = ':' . trim($ports[0]);
} else {
$port = ':' . $server['HTTP_X_FORWARDED_PORT'];
}
} }
return $scheme.'://'.$server['SERVER_NAME'].$port; return $scheme.'://'.$server['SERVER_NAME'].$port;

View file

@ -67,6 +67,19 @@ public function testHttpsProxyForward()
) )
) )
); );
$this->assertEquals(
'https://host.tld:4974',
server_url(
array(
'HTTPS' => 'Off',
'SERVER_NAME' => 'host.tld',
'SERVER_PORT' => '80',
'HTTP_X_FORWARDED_PROTO' => 'https, https',
'HTTP_X_FORWARDED_PORT' => '4974, 80'
)
)
);
} }
/** /**