comparison mod_http_upload/mod_http_upload.lua @ 2286:0a3f526779a1

mod_http_upload: Construct the upload slot URL using the LuaSocket URL library (fixes #717)
author Kim Alvefur <zash@zash.se>
date Tue, 23 Aug 2016 00:44:14 +0200
parents f1923bf329a3
children e1a8c2324937
comparison
equal deleted inserted replaced
2285:f1923bf329a3 2286:0a3f526779a1
9 9
10 -- imports 10 -- imports
11 local st = require"util.stanza"; 11 local st = require"util.stanza";
12 local lfs = require"lfs"; 12 local lfs = require"lfs";
13 local uuid = require"util.uuid".generate; 13 local uuid = require"util.uuid".generate;
14 local urlencode = require"util.http".urlencode; 14 local url = require "socket.url";
15 local dataform = require "util.dataforms".new; 15 local dataform = require "util.dataforms".new;
16 local t_concat = table.concat; 16 local t_concat = table.concat;
17 local t_insert = table.insert; 17 local t_insert = table.insert;
18 local s_upper = string.upper; 18 local s_upper = string.upper;
19 19
83 end 83 end
84 local reply = st.reply(stanza); 84 local reply = st.reply(stanza);
85 reply:tag("slot", { xmlns = xmlns_http_upload }); 85 reply:tag("slot", { xmlns = xmlns_http_upload });
86 local random = uuid(); 86 local random = uuid();
87 pending_slots[random.."/"..filename] = origin.full_jid; 87 pending_slots[random.."/"..filename] = origin.full_jid;
88 local url = module:http_url() .. "/" .. random .. "/" .. urlencode(filename); 88 local base_url = module:http_url();
89 reply:tag("get"):text(url):up(); 89 local slot_url = url.parse(base_url);
90 reply:tag("put"):text(url):up(); 90 slot_url.path = url.parse_path(slot_url.path);
91 t_insert(slot_url.path, random);
92 t_insert(slot_url.path, filename);
93 slot_url.path.is_directory = false;
94 slot_url.path = url.build_path(slot_url.path);
95 slot_url = url.build(slot_url);
96 reply:tag("get"):text(slot_url):up();
97 reply:tag("put"):text(slot_url):up();
91 origin.send(reply); 98 origin.send(reply);
92 origin.log("debug", "Given upload slot %q", random); 99 origin.log("debug", "Given upload slot %q", random);
93 return true; 100 return true;
94 end); 101 end);
95 102