Software /
code /
prosody
Comparison
plugins/mod_http_files.lua @ 4869:1fac86aab90b
Merge with Zash
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Sat, 12 May 2012 03:36:15 +0100 |
parent | 4868:550f0a5e85c5 |
child | 5232:c9bb5879e193 |
comparison
equal
deleted
inserted
replaced
4867:b4219d987d05 | 4869:1fac86aab90b |
---|---|
25 css = "text/css"; | 25 css = "text/css"; |
26 }; | 26 }; |
27 | 27 |
28 function serve_file(event, path) | 28 function serve_file(event, path) |
29 local response = event.response; | 29 local response = event.response; |
30 local orig_path = event.request.path; | |
30 local full_path = http_base.."/"..path; | 31 local full_path = http_base.."/"..path; |
31 if stat(full_path, "mode") == "directory" then | 32 if stat(full_path, "mode") == "directory" then |
32 if stat(full_path.."/index.html", "mode") == "file" then | 33 if full_path:sub(-1) ~= "/" then |
33 return serve_file(event, path.."/index.html"); | 34 response.headers.location = orig_path.."/"; |
35 return 301; | |
34 end | 36 end |
37 if stat(full_path.."index.html", "mode") == "file" then | |
38 return serve_file(event, path.."index.html"); | |
39 end | |
40 | |
41 -- TODO File listing | |
35 return 403; | 42 return 403; |
36 end | 43 end |
37 local f, err = open(full_path, "rb"); | 44 local f, err = open(full_path, "rb"); |
38 if not f then | 45 if not f then |
39 module:log("warn", "Failed to open file: %s", err); | 46 module:log("warn", "Failed to open file: %s", err); |