- if not show_file_list 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();
+ local data = cache[orig_path];
+ if data and data.etag == etag then
+ response_headers.content_type = data.content_type;
+ data = data.data;
+ elseif attr.mode == "directory" and path then
+ if full_path:sub(-1) ~= "/" then
+ local path = { is_absolute = true, is_directory = true };
+ for dir in orig_path:gmatch("[^/]+") do path[#path+1]=dir; end
+ response_headers.location = build_path(path);
+ return 301;
+ end
+ for i=1,#dir_indices do
+ if stat(full_path..dir_indices[i], "mode") == "file" then
+ return serve_file(event, path..dir_indices[i]);