plugins/mod_http_files.lua
changeset 4868 550f0a5e85c5
parent 4722 1138fd3d5846
child 5232 c9bb5879e193
--- a/plugins/mod_http_files.lua	Sat May 12 00:33:04 2012 +0100
+++ b/plugins/mod_http_files.lua	Sat May 12 02:17:08 2012 +0200
@@ -27,11 +27,18 @@
 
 function serve_file(event, path)
 	local response = event.response;
+	local orig_path = event.request.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");
+		if full_path:sub(-1) ~= "/" then
+			response.headers.location = orig_path.."/";
+			return 301;
 		end
+		if stat(full_path.."index.html", "mode") == "file" then
+			return serve_file(event, path.."index.html");
+		end
+
+		-- TODO File listing
 		return 403;
 	end
 	local f, err = open(full_path, "rb");