Changeset

9502:09e7b0048ebe

mod_http: Make sure path from http_external_url always ends with a slash (fixes #1183)
author Kim Alvefur <zash@zash.se>
date Sun, 14 Oct 2018 14:01:57 +0200
parents 9280:37b796cc366a
children 9503:3456496d5218 9543:92bfb12684b0
files plugins/mod_http.lua
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_http.lua	Sat Sep 08 11:46:02 2018 +0200
+++ b/plugins/mod_http.lua	Sun Oct 14 14:01:57 2018 +0200
@@ -21,8 +21,12 @@
 server.set_option("body_size_limit", module:get_option_number("http_max_content_size"));
 server.set_option("buffer_size_limit", module:get_option_number("http_max_buffer_size"));
 
-local function normalize_path(path)
-	if path:sub(-1,-1) == "/" then path = path:sub(1, -2); end
+local function normalize_path(path, is_dir)
+	if is_dir then
+		if path:sub(-1,-1) ~= "/" then path = path.."/"; end
+	else
+		if path:sub(-1,-1) == "/" then path = path:sub(1, -2); end
+	end
 	if path:sub(1,1) ~= "/" then path = "/"..path; end
 	return path;
 end
@@ -70,7 +74,7 @@
 				scheme = (external_url.scheme or services[1].service.name);
 				host = (external_url.host or module:get_option_string("http_host", module.host));
 				port = tonumber(external_url.port) or port or 80;
-				path = normalize_path(external_url.path or "/")..
+				path = normalize_path(external_url.path or "/", true)..
 					(get_base_path(module, app_name, default_path or "/"..app_name):sub(2));
 			}
 			if ports_by_scheme[url.scheme] == url.port then url.port = nil end