# HG changeset patch # User Florian Zeitz # Date 1294353705 -3600 # Node ID 5ec9125575fc2ff14b07f4a01de51bf9eab73ce4 # Parent f406e300d7090559fabc8e30ada3e833a38d00c3 mod_admin_web: Handle paths without trailing slash diff -r f406e300d709 -r 5ec9125575fc mod_admin_web/admin_web/mod_admin_web.lua --- a/mod_admin_web/admin_web/mod_admin_web.lua Thu Jan 06 21:29:15 2011 +0100 +++ b/mod_admin_web/admin_web/mod_admin_web.lua Thu Jan 06 23:41:45 2011 +0100 @@ -30,6 +30,7 @@ local xmlns_c2s_session = "http://prosody.im/streams/c2s"; local xmlns_s2s_session = "http://prosody.im/streams/s2s"; +local response_301 = { status = "301 Moved Permanently" }; local response_400 = { status = "400 Bad Request", body = "

Bad Request

Sorry, we didn't understand your request :(" }; local response_403 = { status = "403 Forbidden", body = "

Forbidden

You don't have permission to view the contents of this directory :(" }; local response_404 = { status = "404 Not Found", body = "

Page Not Found

Sorry, we couldn't find what you were looking for :(" }; @@ -116,9 +117,14 @@ return path; end -function serve_file(path) +function serve_file(path, base) local full_path = http_base..path; if stat(full_path, "mode") == "directory" then + if not path:find("/$") then + local response = response_301; + response.headers = { ["Location"] = base .. "/" }; + return response; + end if stat(full_path.."/index.html", "mode") == "file" then return serve_file(path.."/index.html"); end @@ -143,8 +149,8 @@ local function handle_file_request(method, body, request) local path = preprocess_path(request.url.path); if not path then return response_400; end - path = path:gsub("^/[^/]+", ""); -- Strip /admin/ - return serve_file(path); + path_stripped = path:gsub("^/[^/]+", ""); -- Strip /admin/ + return serve_file(path_stripped, path); end function module.load()