Merge pull request #505 from ArthurHoaro/hotfix/multi-reverse-proxy
Fixes #477: support multi reverse proxy with comma syntax
This commit is contained in:
commit
6e7a3210c3
2 changed files with 25 additions and 2 deletions
|
@ -106,11 +106,21 @@ function server_url($server)
|
|||
// Shaarli is served behind a proxy
|
||||
if (isset($server['HTTP_X_FORWARDED_PROTO'])) {
|
||||
// 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'])) {
|
||||
// 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;
|
||||
|
|
|
@ -67,6 +67,19 @@ class ServerUrlTest extends PHPUnit_Framework_TestCase
|
|||
)
|
||||
)
|
||||
);
|
||||
|
||||
$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'
|
||||
)
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue