aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2012-04-26 16:48:16 +0100
committerMatthew Wild <mwild1@gmail.com>2012-04-26 16:48:16 +0100
commit7c5c2aea2ca88a0112c51c5eaf74209271d780c9 (patch)
tree7db3b0608d0e9271c3f2827877ee249c3744921a
parent26768dfb4dd3682d63b9715c8942b827d52ffd12 (diff)
downloadprosody-7c5c2aea2ca88a0112c51c5eaf74209271d780c9.tar.gz
prosody-7c5c2aea2ca88a0112c51c5eaf74209271d780c9.zip
mod_http_files, net.http.parser: Move path normalization to net.http.parser so that all modules can benefit
-rw-r--r--net/http/parser.lua20
-rw-r--r--plugins/mod_http_files.lua24
2 files changed, 20 insertions, 24 deletions
diff --git a/net/http/parser.lua b/net/http/parser.lua
index fdcb8ebb..3d9d1a87 100644
--- a/net/http/parser.lua
+++ b/net/http/parser.lua
@@ -2,6 +2,24 @@
local tonumber = tonumber;
local assert = assert;
+local function preprocess_path(path)
+ if path:sub(1,1) ~= "/" then
+ path = "/"..path;
+ end
+ local level = 0;
+ for component in path:gmatch("([^/]+)/") do
+ if component == ".." then
+ level = level - 1;
+ elseif component ~= "." then
+ level = level + 1;
+ end
+ if level < 0 then
+ return nil;
+ end
+ end
+ return path;
+end
+
local httpstream = {};
function httpstream.new(success_cb, error_cb, parser_type, options_cb)
@@ -74,7 +92,7 @@ function httpstream.new(success_cb, error_cb, parser_type, options_cb)
if path:match("^https?://") then
headers.host, path = path:match("^https?://([^/]*)(.*)");
end
- path = path:gsub("^//+", "/"); -- TODO parse url more
+ path = preprocess_path(path);
len = len or 0;
packet = {
diff --git a/plugins/mod_http_files.lua b/plugins/mod_http_files.lua
index 932d2547..9be735b7 100644
--- a/plugins/mod_http_files.lua
+++ b/plugins/mod_http_files.lua
@@ -25,31 +25,9 @@ local mime_map = {
css = "text/css";
};
-local function preprocess_path(path)
- if path:sub(1,1) ~= "/" then
- path = "/"..path;
- end
- local level = 0;
- for component in path:gmatch("([^/]+)/") do
- if component == ".." then
- level = level - 1;
- elseif component ~= "." then
- level = level + 1;
- end
- if level < 0 then
- return nil;
- end
- end
- return path;
-end
-
function serve_file(event, path)
local response = event.response;
- path = path and preprocess_path(path);
- if not path then
- return 400;
- end
- local full_path = http_base..path;
+ local full_path = http_base.."/"..path;
if stat(full_path, "mode") == "directory" then
if stat(full_path.."/index.html", "mode") == "file" then
return serve_file(event, path.."/index.html");