aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_http_files.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2012-12-11 22:26:41 +0100
committerKim Alvefur <zash@zash.se>2012-12-11 22:26:41 +0100
commit896dda62653222978ed0cf849ca950d7963a6db4 (patch)
treefa91349de89bb33bd6b7c013453782fbc99db18c /plugins/mod_http_files.lua
parentd623c4a3e2f1da496fbad6c73ad6ce1a0e0a3979 (diff)
downloadprosody-896dda62653222978ed0cf849ca950d7963a6db4.tar.gz
prosody-896dda62653222978ed0cf849ca950d7963a6db4.zip
mod_http_files: Return 404 faster if file does not exist
Diffstat (limited to 'plugins/mod_http_files.lua')
-rw-r--r--plugins/mod_http_files.lua12
1 files changed, 9 insertions, 3 deletions
diff --git a/plugins/mod_http_files.lua b/plugins/mod_http_files.lua
index 62cb39b2..8d3405c9 100644
--- a/plugins/mod_http_files.lua
+++ b/plugins/mod_http_files.lua
@@ -27,10 +27,15 @@ local mime_map = {
};
function serve_file(event, path)
- local response = event.response;
- local orig_path = event.request.path;
+ local request, response = event.request, event.response;
+ local orig_path = request.path;
local full_path = http_base.."/"..path;
- if stat(full_path, "mode") == "directory" then
+ local attr = stat(full_path);
+ if not attr then
+ return 404;
+ end
+
+ if attr.mode == "directory" then
if full_path:sub(-1) ~= "/" then
response.headers.location = orig_path.."/";
return 301;
@@ -44,6 +49,7 @@ function serve_file(event, path)
-- TODO File listing
return 403;
end
+
local f, err = open(full_path, "rb");
if not f then
module:log("warn", "Failed to open file: %s", err);