Comparison

plugins/mod_http_files.lua @ 5232:c9bb5879e193

mod_http_files: Configurable number of index files to check for
author Kim Alvefur <zash@zash.se>
date Tue, 11 Dec 2012 22:14:55 +0100
parent 4868:550f0a5e85c5
child 5233:342c46e62f50
comparison
equal deleted inserted replaced
5230:6f5640375358 5232:c9bb5879e193
11 11
12 local open = io.open; 12 local open = io.open;
13 local stat = lfs.attributes; 13 local stat = lfs.attributes;
14 14
15 local http_base = module:get_option_string("http_files_dir", module:get_option_string("http_path", "www_files")); 15 local http_base = module:get_option_string("http_files_dir", module:get_option_string("http_path", "www_files"));
16 local dir_indices = module:get_option("http_files_index", { "index.html", "index.htm" });
16 17
17 -- TODO: Should we read this from /etc/mime.types if it exists? (startup time...?) 18 -- TODO: Should we read this from /etc/mime.types if it exists? (startup time...?)
18 local mime_map = { 19 local mime_map = {
19 html = "text/html"; 20 html = "text/html";
20 htm = "text/html"; 21 htm = "text/html";
32 if stat(full_path, "mode") == "directory" then 33 if stat(full_path, "mode") == "directory" then
33 if full_path:sub(-1) ~= "/" then 34 if full_path:sub(-1) ~= "/" then
34 response.headers.location = orig_path.."/"; 35 response.headers.location = orig_path.."/";
35 return 301; 36 return 301;
36 end 37 end
37 if stat(full_path.."index.html", "mode") == "file" then 38 for i=1,#dir_indices do
38 return serve_file(event, path.."index.html"); 39 if stat(full_path..dir_indices[i], "mode") == "file" then
40 return serve_file(event, path..dir_indices[i]);
41 end
39 end 42 end
40 43
41 -- TODO File listing 44 -- TODO File listing
42 return 403; 45 return 403;
43 end 46 end