Mercurial > prosody-hg
comparison plugins/mod_http_files.lua @ 9951:f1594893998f
mod_http_files: Try to determine which module using serve() needs updating
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Fri, 05 Apr 2019 18:18:23 +0200 |
| parents | afc48785f738 |
| children | c88f979946c4 |
comparison
equal
deleted
inserted
replaced
| 9950:afc48785f738 | 9951:f1594893998f |
|---|---|
| 44 end | 44 end |
| 45 }); | 45 }); |
| 46 end | 46 end |
| 47 end | 47 end |
| 48 | 48 |
| 49 local function get_calling_module() | |
| 50 local info = debug.getinfo(3, "S"); | |
| 51 if not info then return "An unknown module"; end | |
| 52 return info.source:match"mod_[^/\\.]+" or info.short_src; | |
| 53 end | |
| 54 | |
| 49 -- COMPAT -- TODO deprecate | 55 -- COMPAT -- TODO deprecate |
| 50 function serve(opts) | 56 function serve(opts) |
| 51 if type(opts) ~= "table" then -- assume path string | 57 if type(opts) ~= "table" then -- assume path string |
| 52 opts = { path = opts }; | 58 opts = { path = opts }; |
| 53 end | 59 end |
| 65 end | 71 end |
| 66 if opts.index_files == nil then | 72 if opts.index_files == nil then |
| 67 opts.index_files = dir_indices; | 73 opts.index_files = dir_indices; |
| 68 end | 74 end |
| 69 -- TODO Crank up to warning | 75 -- TODO Crank up to warning |
| 70 module:log("debug", "Use of mod_http_files.serve() should be updated to use net.http.files"); | 76 module:log("debug", "%s should be updated to use 'net.http.files' insead of mod_http_files", get_calling_module()); |
| 71 return fileserver.serve(opts); | 77 return fileserver.serve(opts); |
| 72 end | 78 end |
| 73 | 79 |
| 74 function wrap_route(routes) | 80 function wrap_route(routes) |
| 75 module:log("debug", "Use of mod_http_files.wrap_route() should be updated to use net.http.files"); | 81 module:log("debug", "%s should be updated to use 'net.http.files' insead of mod_http_files", get_calling_module()); |
| 76 for route,handler in pairs(routes) do | 82 for route,handler in pairs(routes) do |
| 77 if type(handler) ~= "function" then | 83 if type(handler) ~= "function" then |
| 78 routes[route] = fileserver.serve(handler); | 84 routes[route] = fileserver.serve(handler); |
| 79 end | 85 end |
| 80 end | 86 end |
