// 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;
)
)
);
+
+ $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'
+ )
+ )
+ );
}
/**