# HG changeset patch # User Kim Alvefur # Date 1356116913 -3600 # Node ID 736e7ec8cd2e71347dfec5e1a26b89cf0cb4104e # Parent 4e58fde55594a8070fb3bcaeb33f2796b6c5ee7c mod_http_files: Replace file listing with an event, allowing a different plugin to generate it diff -r 4e58fde55594 -r 736e7ec8cd2e plugins/mod_http_files.lua --- a/plugins/mod_http_files.lua Fri Dec 21 17:54:43 2012 +0100 +++ b/plugins/mod_http_files.lua Fri Dec 21 20:08:33 2012 +0100 @@ -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 @@ 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 = "\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");