Software /
code /
prosody
Diff
plugins/mod_http_files.lua @ 4868:550f0a5e85c5
mod_http_files: Respond with a 301 redirect for directories to append a / (fixes relative links)
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 12 May 2012 02:17:08 +0200 |
parent | 4722:1138fd3d5846 |
child | 5232:c9bb5879e193 |
line wrap: on
line diff
--- 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");