aboutsummaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-01-28 16:23:38 +0100
committerKim Alvefur <zash@zash.se>2021-01-28 16:23:38 +0100
commit318d357557d2c219f33c5631d73c029619bf0d2b (patch)
tree01ed8b22132c139e3e278e1820c7ebb1c311b51e /plugins
parent217450a7270d70cde4216058a7c3fadac83bfbb0 (diff)
downloadprosody-318d357557d2c219f33c5631d73c029619bf0d2b.tar.gz
prosody-318d357557d2c219f33c5631d73c029619bf0d2b.zip
mod_http_file_share: Extract all file properties into variables earlier
A step towards adding caching, which will unpack into the same variables.
Diffstat (limited to 'plugins')
-rw-r--r--plugins/mod_http_file_share.lua16
1 files changed, 12 insertions, 4 deletions
diff --git a/plugins/mod_http_file_share.lua b/plugins/mod_http_file_share.lua
index 6b9ccace..23454e57 100644
--- a/plugins/mod_http_file_share.lua
+++ b/plugins/mod_http_file_share.lua
@@ -227,13 +227,21 @@ function handle_download(event, path) -- GET /uploads/:slot+filename
local request, response = event.request, event.response;
local slot_id = path:match("^[^/]+");
-- TODO cache
+ local basename, filetime, filetype, filesize;
local slot, when = errors.coerce(uploads:get(nil, slot_id));
if not slot then
module:log("debug", "uploads:get(%q) --> not-found, %s", slot_id, when);
+ else
+ basename = slot.attr.filename;
+ filesize = slot.attr.size;
+ filetype = slot.attr["content-type"];
+ filetime = when;
+ end
+ if not basename then
return 404;
end
module:log("debug", "uploads:get(%q) --> %s, %d", slot_id, slot, when);
- local last_modified = os.date('!%a, %d %b %Y %H:%M:%S GMT', when);
+ local last_modified = os.date('!%a, %d %b %Y %H:%M:%S GMT', filetime);
if request.headers.if_modified_since == last_modified then
return 304;
end
@@ -243,9 +251,9 @@ function handle_download(event, path) -- GET /uploads/:slot+filename
return ferr or 410;
end
response.headers.last_modified = last_modified;
- response.headers.content_length = slot.attr.size;
- response.headers.content_type = slot.attr["content-type"] or "application/octet-stream";
- response.headers.content_disposition = string.format("attachment; filename=%q", slot.attr.filename);
+ response.headers.content_length = filesize;
+ response.headers.content_type = filetype or "application/octet-stream";
+ response.headers.content_disposition = string.format("attachment; filename=%q", basename);
response.headers.cache_control = "max-age=31556952, immutable";
response.headers.content_security_policy = "default-src 'none'; frame-ancestors 'none';"