Changeset

9504:cfbea3064aa9

mod_http: Move normalize_path to util.http
author Kim Alvefur <zash@zash.se>
date Sun, 14 Oct 2018 14:31:59 +0200
parents 9503:3456496d5218
children 9505:5203b6fd34d4
files plugins/mod_http.lua util/http.lua
diffstat 2 files changed, 12 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/plugins/mod_http.lua	Sun Oct 14 14:19:21 2018 +0200
+++ b/plugins/mod_http.lua	Sun Oct 14 14:31:59 2018 +0200
@@ -13,6 +13,7 @@
 local moduleapi = require "core.moduleapi";
 local url_parse = require "socket.url".parse;
 local url_build = require "socket.url".build;
+local normalize_path = require "util.http".normalize_path;
 
 local server = require "net.http.server";
 
@@ -21,16 +22,6 @@
 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, 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
-
 local function get_http_event(host, app_path, key)
 	local method, path = key:match("^(%S+)%s+(.+)$");
 	if not method then -- No path specified, default to "" (base path)
--- a/util/http.lua	Sun Oct 14 14:19:21 2018 +0200
+++ b/util/http.lua	Sun Oct 14 14:31:59 2018 +0200
@@ -57,8 +57,19 @@
 	return field:find(","..token:lower()..",", 1, true) ~= nil;
 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
+
 return {
 	urlencode = urlencode, urldecode = urldecode;
 	formencode = formencode, formdecode = formdecode;
 	contains_token = contains_token;
+	normalize_path = normalize_path;
 };