projects
/
prosody.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
mod_s2s: Log certificate identity validation result
[prosody.git]
/
util
/
http.lua
diff --git
a/util/http.lua
b/util/http.lua
index 5dd636d9d25b28f82ac3d0ee649216dce7115c42..f725992090a424998e59a7423df04d73c49d6d4e 100644
(file)
--- a/
util/http.lua
+++ b/
util/http.lua
@@
-5,12
+5,14
@@
-- COPYING file in the source package for more information.
--
-- COPYING file in the source package for more information.
--
-local http = {};
+local format, char = string.format, string.char;
+local pairs, ipairs, tonumber = pairs, ipairs, tonumber;
+local t_insert, t_concat = table.insert, table.concat;
-
function http.
urlencode(s)
+
local function
urlencode(s)
return s and (s:gsub("[^a-zA-Z0-9.~_-]", function (c) return format("%%%02x", c:byte()); end));
end
return s and (s:gsub("[^a-zA-Z0-9.~_-]", function (c) return format("%%%02x", c:byte()); end));
end
-
function http.
urldecode(s)
+
local function
urldecode(s)
return s and (s:gsub("%%(%x%x)", function (c) return char(tonumber(c,16)); end));
end
return s and (s:gsub("%%(%x%x)", function (c) return char(tonumber(c,16)); end));
end
@@
-24,7
+26,7
@@
local function _formencodepart(s)
end));
end
end));
end
-
function http.
formencode(form)
+
local function
formencode(form)
local result = {};
if form[1] then -- Array of ordered { name, value }
for _, field in ipairs(form) do
local result = {};
if form[1] then -- Array of ordered { name, value }
for _, field in ipairs(form) do
@@
-38,7
+40,7
@@
function http.formencode(form)
return t_concat(result, "&");
end
return t_concat(result, "&");
end
-
function http.
formdecode(s)
+
local function
formdecode(s)
if not s:match("=") then return urldecode(s); end
local r = {};
for k, v in s:gmatch("([^=&]*)=([^&]*)") do
if not s:match("=") then return urldecode(s); end
local r = {};
for k, v in s:gmatch("([^=&]*)=([^&]*)") do
@@
-50,11
+52,13
@@
function http.formdecode(s)
return r;
end
return r;
end
-
function http.
contains_token(field, token)
+
local function
contains_token(field, token)
field = ","..field:gsub("[ \t]", ""):lower()..",";
return field:find(","..token:lower()..",", 1, true) ~= nil;
end
field = ","..field:gsub("[ \t]", ""):lower()..",";
return field:find(","..token:lower()..",", 1, true) ~= nil;
end
-
-
-return http;
+return {
+ urlencode = urlencode, urldecode = urldecode;
+ formencode = formencode, formdecode = formdecode;
+ contains_token = contains_token;
+};