Software /
code /
prosody
Changeset
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 |
parents | 4863:8974a9b7363f |
children | 4869:1fac86aab90b |
files | plugins/mod_http_files.lua |
diffstat | 1 files changed, 9 insertions(+), 2 deletions(-) [+] |
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");