Software / code / prosody
Comparison
plugins/mod_http_files.lua @ 5261:b14f02671439
mod_http_files: Rename config options and variable names
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 21 Dec 2012 17:22:19 +0100 |
| parent | 5260:87f72452a893 |
| child | 5262:4e58fde55594 |
comparison
equal
deleted
inserted
replaced
| 5260:87f72452a893 | 5261:b14f02671439 |
|---|---|
| 12 local os_date = os.date; | 12 local os_date = os.date; |
| 13 local open = io.open; | 13 local open = io.open; |
| 14 local stat = lfs.attributes; | 14 local stat = lfs.attributes; |
| 15 local build_path = require"socket.url".build_path; | 15 local build_path = require"socket.url".build_path; |
| 16 | 16 |
| 17 local http_base = module:get_option_string("http_files_dir", module:get_option_string("http_path", "www_files")); | 17 local base_path = module:get_option_string("http_files_dir", module:get_option_string("http_path", "www_files")); |
| 18 local dir_indices = module:get_option("http_files_index", { "index.html", "index.htm" }); | 18 local dir_indices = module:get_option("http_index_files", { "index.html", "index.htm" }); |
| 19 local show_file_list = module:get_option_boolean("http_files_show_list"); | 19 local directory_index = module:get_option_boolean("http_dir_listing"); |
| 20 | 20 |
| 21 local mime_map = module:shared("mime").types; | 21 local mime_map = module:shared("mime").types; |
| 22 if not mime_map then | 22 if not mime_map then |
| 23 mime_map = { | 23 mime_map = { |
| 24 html = "text/html", htm = "text/html", | 24 html = "text/html", htm = "text/html", |
| 50 local cache = setmetatable({}, { __mode = "kv" }); -- Let the garbage collector have it if it wants to. | 50 local cache = setmetatable({}, { __mode = "kv" }); -- Let the garbage collector have it if it wants to. |
| 51 | 51 |
| 52 function serve_file(event, path) | 52 function serve_file(event, path) |
| 53 local request, response = event.request, event.response; | 53 local request, response = event.request, event.response; |
| 54 local orig_path = request.path; | 54 local orig_path = request.path; |
| 55 local full_path = http_base.."/"..path; | 55 local full_path = base_path.."/"..path; |
| 56 local attr = stat(full_path); | 56 local attr = stat(full_path); |
| 57 if not attr then | 57 if not attr then |
| 58 return 404; | 58 return 404; |
| 59 end | 59 end |
| 60 | 60 |
| 88 if stat(full_path..dir_indices[i], "mode") == "file" then | 88 if stat(full_path..dir_indices[i], "mode") == "file" then |
| 89 return serve_file(event, path..dir_indices[i]); | 89 return serve_file(event, path..dir_indices[i]); |
| 90 end | 90 end |
| 91 end | 91 end |
| 92 | 92 |
| 93 if not show_file_list then | 93 if not directory_index then |
| 94 return 403; | 94 return 403; |
| 95 else | 95 else |
| 96 local html = require"util.stanza".stanza("html") | 96 local html = require"util.stanza".stanza("html") |
| 97 :tag("head"):tag("title"):text(path):up() | 97 :tag("head"):tag("title"):text(path):up() |
| 98 :tag("meta", { charset="utf-8" }):up() | 98 :tag("meta", { charset="utf-8" }):up() |