Software / code / prosody
Comparison
plugins/mod_http_files.lua @ 6030:9b91242cc137
mod_http_files: Strip path separator from end of paths, was broken on Windows (thanks Junne)
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Sun, 09 Mar 2014 22:16:44 +0100 |
| parent | 5716:8a0465de172e |
| child | 6031:8796aa94c4b5 |
| child | 6872:eb28067faadf |
comparison
equal
deleted
inserted
replaced
| 6029:dd3d4cfbd3cb | 6030:9b91242cc137 |
|---|---|
| 12 | 12 |
| 13 local os_date = os.date; | 13 local os_date = os.date; |
| 14 local open = io.open; | 14 local open = io.open; |
| 15 local stat = lfs.attributes; | 15 local stat = lfs.attributes; |
| 16 local build_path = require"socket.url".build_path; | 16 local build_path = require"socket.url".build_path; |
| 17 local path_sep = package.config:sub(1,1); | |
| 17 | 18 |
| 18 local base_path = module:get_option_string("http_files_dir", module:get_option_string("http_path")); | 19 local base_path = module:get_option_string("http_files_dir", module:get_option_string("http_path")); |
| 19 local dir_indices = module:get_option("http_index_files", { "index.html", "index.htm" }); | 20 local dir_indices = module:get_option("http_index_files", { "index.html", "index.htm" }); |
| 20 local directory_index = module:get_option_boolean("http_dir_listing"); | 21 local directory_index = module:get_option_boolean("http_dir_listing"); |
| 21 | 22 |
| 59 local directory_index = opts.directory_index; | 60 local directory_index = opts.directory_index; |
| 60 local function serve_file(event, path) | 61 local function serve_file(event, path) |
| 61 local request, response = event.request, event.response; | 62 local request, response = event.request, event.response; |
| 62 local orig_path = request.path; | 63 local orig_path = request.path; |
| 63 local full_path = base_path .. (path and "/"..path or ""); | 64 local full_path = base_path .. (path and "/"..path or ""); |
| 64 local attr = stat(full_path); | 65 local attr = stat((full_path:gsub('%'..path_sep..'+$',''))); |
| 65 if not attr then | 66 if not attr then |
| 66 return 404; | 67 return 404; |
| 67 end | 68 end |
| 68 | 69 |
| 69 local request_headers, response_headers = request.headers, response.headers; | 70 local request_headers, response_headers = request.headers, response.headers; |