Software /
code /
prosody-modules
Comparison
mod_http_upload/mod_http_upload.lua @ 3625:a578b4977bb0
mod_http_upload: Duplicate mime types handling from mod_http_files (fixes #1374)
When using net.http.files this isn't automatically provided via
mod_http_files so we need to do it ourselves.
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sat, 29 Jun 2019 19:26:08 +0200 |
parent | 3590:d8cc8b71a199 |
child | 3648:aa12b95a6d36 |
comparison
equal
deleted
inserted
replaced
3624:3109a65ab7f4 | 3625:a578b4977bb0 |
---|---|
48 | 48 |
49 if not pcall(function () | 49 if not pcall(function () |
50 http_files = require "net.http.files"; | 50 http_files = require "net.http.files"; |
51 end) then | 51 end) then |
52 http_files = module:depends"http_files"; | 52 http_files = module:depends"http_files"; |
53 end | |
54 | |
55 local mime_map = module:shared("/*/http_files/mime").types; | |
56 if not mime_map then | |
57 mime_map = { | |
58 html = "text/html", htm = "text/html", | |
59 xml = "application/xml", | |
60 txt = "text/plain", | |
61 css = "text/css", | |
62 js = "application/javascript", | |
63 png = "image/png", | |
64 gif = "image/gif", | |
65 jpeg = "image/jpeg", jpg = "image/jpeg", | |
66 svg = "image/svg+xml", | |
67 }; | |
68 module:shared("/*/http_files/mime").types = mime_map; | |
69 | |
70 local mime_types, err = io.open(module:get_option_path("mime_types_file", "/etc/mime.types", "config"), "r"); | |
71 if mime_types then | |
72 local mime_data = mime_types:read("*a"); | |
73 mime_types:close(); | |
74 setmetatable(mime_map, { | |
75 __index = function(t, ext) | |
76 local typ = mime_data:match("\n(%S+)[^\n]*%s"..(ext:lower()).."%s") or "application/octet-stream"; | |
77 t[ext] = typ; | |
78 return typ; | |
79 end | |
80 }); | |
81 end | |
53 end | 82 end |
54 | 83 |
55 -- namespaces | 84 -- namespaces |
56 local namespace = "urn:xmpp:http:upload:0"; | 85 local namespace = "urn:xmpp:http:upload:0"; |
57 local legacy_namespace = "urn:xmpp:http:upload"; | 86 local legacy_namespace = "urn:xmpp:http:upload"; |
340 else | 369 else |
341 response.conn:close(); | 370 response.conn:close(); |
342 end | 371 end |
343 end | 372 end |
344 | 373 |
345 local serve_uploaded_files = http_files.serve(storage_path); | 374 local serve_uploaded_files = http_files.serve({ path = storage_path, mime_map = mime_map }); |
346 | 375 |
347 local function serve_head(event, path) | 376 local function serve_head(event, path) |
348 set_cross_domain_headers(event.response); | 377 set_cross_domain_headers(event.response); |
349 event.response.send = send_response_sans_body; | 378 event.response.send = send_response_sans_body; |
350 event.response.send_file = send_response_sans_body; | 379 event.response.send_file = send_response_sans_body; |