aboutsummaryrefslogtreecommitdiffstats
path: root/plugins/mod_http_files.lua
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2012-12-21 20:08:33 +0100
committerKim Alvefur <zash@zash.se>2012-12-21 20:08:33 +0100
commit88d386b8dd9b29bd2ec20544d515dac5b2e39442 (patch)
treeaac1e485b30df1ff8aadf90b0237ea63f2240410 /plugins/mod_http_files.lua
parentab4685492f702226443cd483bb4b89233ccc15be (diff)
downloadprosody-88d386b8dd9b29bd2ec20544d515dac5b2e39442.tar.gz
prosody-88d386b8dd9b29bd2ec20544d515dac5b2e39442.zip
mod_http_files: Replace file listing with an event, allowing a different plugin to generate it
Diffstat (limited to 'plugins/mod_http_files.lua')
-rw-r--r--plugins/mod_http_files.lua26
1 files changed, 7 insertions, 19 deletions
diff --git a/plugins/mod_http_files.lua b/plugins/mod_http_files.lua
index 1de58407..bd39936d 100644
--- a/plugins/mod_http_files.lua
+++ b/plugins/mod_http_files.lua
@@ -7,6 +7,7 @@
--
module:depends("http");
+local server = require"net.http.server";
local lfs = require "lfs";
local os_date = os.date;
@@ -94,27 +95,14 @@ function serve(opts)
end
end
- if not directory_index then
+ if directory_index then
+ data = server._events.fire_event("directory-index", { path = request.path, full_path = full_path });
+ end
+ if not data then
return 403;
- else
- local html = require"util.stanza".stanza("html")
- :tag("head"):tag("title"):text(path):up()
- :tag("meta", { charset="utf-8" }):up()
- :up()
- :tag("body"):tag("h1"):text(path):up()
- :tag("ul");
- for file in lfs.dir(full_path) do
- if file:sub(1,1) ~= "." then
- local attr = stat(full_path..file) or {};
- html:tag("li", { class = attr.mode })
- :tag("a", { href = file }):text(file)
- :up():up();
- end
- end
- data = "<!DOCTYPE html>\n"..tostring(html);
- cache[path] = { data = data, content_type = mime_map.html; etag = etag; };
- response_headers.content_type = mime_map.html;
end
+ cache[path] = { data = data, content_type = mime_map.html; etag = etag; };
+ response_headers.content_type = mime_map.html;
else
local f, err = open(full_path, "rb");