From e0355fa7057bbe3aa970845ad0024308792a3cde Mon Sep 17 00:00:00 2001 From: Isaac Besora Vilardaga Date: Tue, 6 Mar 2018 13:49:08 +0100 Subject: [PATCH 1/2] Removes trailing query parameters --- tileserver.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/tileserver.php b/tileserver.php index 350603e..957e8b3 100644 --- a/tileserver.php +++ b/tileserver.php @@ -1240,17 +1240,18 @@ public static function serve($routes) { $xForwarded = true; } } - $config['protocol'] = ((isset($_SERVER['HTTPS']) or (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) or $xForwarded) ? 'https' : 'http'; + $config['protocol'] = ((isset($_SERVER['HTTPS']) or (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) or $xForwarded) ? 'https' : 'http'; + $requestURINoQuery = substr($_SERVER['REQUEST_URI'], 0, strpos( $_SERVER['REQUEST_URI'], '&', strrpos( $_SERVER['REQUEST_URI'], '?'))); if (!empty($_SERVER['PATH_INFO'])) { $path_info = $_SERVER['PATH_INFO']; } else if (!empty($_SERVER['ORIG_PATH_INFO']) && strpos($_SERVER['ORIG_PATH_INFO'], 'tileserver.php') === false) { $path_info = $_SERVER['ORIG_PATH_INFO']; } else if (!empty($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], '/tileserver.php') !== false) { - $path_info = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; - $config['baseUrls'][0] = $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'] . '?'; + $path_info = $_SERVER['HTTP_HOST'] . $requestURINoQuery; + $config['baseUrls'][0] = $_SERVER['HTTP_HOST'] . $requestURINoQuery . '?'; } else { if (!empty($_SERVER['REQUEST_URI'])) { - $path_info = (strpos($_SERVER['REQUEST_URI'], '?') > 0) ? strstr($_SERVER['REQUEST_URI'], '?', true) : $_SERVER['REQUEST_URI']; + $path_info = (strpos($requestURINoQuery, '?') > 0) ? strstr($requestURINoQuery, '?', true) : $requestURINoQuery; } } $discovered_handler = null; From 2f09de22a1da615b46c6938052ba6837b30c1664 Mon Sep 17 00:00:00 2001 From: Isaac Besora Vilardaga Date: Thu, 8 Mar 2018 08:09:45 +0100 Subject: [PATCH 2/2] Minor refactoring --- tileserver.php | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/tileserver.php b/tileserver.php index 957e8b3..4a7cc10 100644 --- a/tileserver.php +++ b/tileserver.php @@ -1233,15 +1233,19 @@ class Router { */ public static function serve($routes) { $path_info = '/'; - global $config; - $xForwarded = false; - if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) { - if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { - $xForwarded = true; - } - } - $config['protocol'] = ((isset($_SERVER['HTTPS']) or (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) or $xForwarded) ? 'https' : 'http'; - $requestURINoQuery = substr($_SERVER['REQUEST_URI'], 0, strpos( $_SERVER['REQUEST_URI'], '&', strrpos( $_SERVER['REQUEST_URI'], '?'))); + global $config; + $xForwarded = false; + if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) { + if ($_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https') { + $xForwarded = true; + } + } + $config['protocol'] = ((isset($_SERVER['HTTPS']) or (isset($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] == 443)) or $xForwarded) ? 'https' : 'http'; + $queryStart = strpos( $_SERVER['REQUEST_URI'], '&', strrpos( $_SERVER['REQUEST_URI'], '?')); + $requestURINoQuery = $_SERVER['REQUEST_URI']; + if ($queryStart != FALSE) { + $requestURINoQuery = substr($_SERVER['REQUEST_URI'], 0, $queryStart); + } if (!empty($_SERVER['PATH_INFO'])) { $path_info = $_SERVER['PATH_INFO']; } else if (!empty($_SERVER['ORIG_PATH_INFO']) && strpos($_SERVER['ORIG_PATH_INFO'], 'tileserver.php') === false) {