X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2FHttpUtils.php;h=88a1efdb86382646648d9a26a2cbeab022f7ecdf;hb=23daed648c94022098794e17fee54b3627b29275;hp=e705cfd6030cb0da7ff5e90bde930433bcecbbe0;hpb=03542572665bae57705a2f57b0737ed43f4f1415;p=github%2Fshaarli%2FShaarli.git diff --git a/application/HttpUtils.php b/application/HttpUtils.php index e705cfd6..88a1efdb 100644 --- a/application/HttpUtils.php +++ b/application/HttpUtils.php @@ -122,7 +122,7 @@ function get_http_response($url, $timeout = 30, $maxBytes = 4194304) $content = substr($response, $headSize); $headers = array(); foreach (preg_split('~[\r\n]+~', $rawHeadersLastRedir) as $line) { - if (empty($line) or ctype_space($line)) { + if (empty($line) || ctype_space($line)) { continue; } $splitLine = explode(': ', $line, 2); @@ -297,13 +297,33 @@ 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 = ''; + } + } + + if (isset($server['HTTP_X_FORWARDED_HOST'])) { + // Keep forwarded host + if (strpos($server['HTTP_X_FORWARDED_HOST'], ',') !== false) { + $hosts = explode(',', $server['HTTP_X_FORWARDED_HOST']); + $host = trim($hosts[0]); + } else { + $host = $server['HTTP_X_FORWARDED_HOST']; + } + } else { + $host = $server['SERVER_NAME']; } - return $scheme.'://'.$server['SERVER_NAME'].$port; + return $scheme.'://'.$host.$port; } // SSL detection