Moved session.lua to http.lus and added Cookie-parser and URL-decoder functions.
This commit is contained in:
parent
b86e8a03bc
commit
cf08430348
2 changed files with 29 additions and 11 deletions
29
lua/xw3/http.lua
Normal file
29
lua/xw3/http.lua
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
|
||||
function max(num1, num2)
|
||||
if (num1 > num2) then
|
||||
result = num1;
|
||||
else
|
||||
result = num2;
|
||||
end
|
||||
return result;
|
||||
end
|
||||
|
||||
function parse_cookies(cookie_str)
|
||||
local cookies = {}
|
||||
for pair in cookie_str:gmatch("[^;]+") do
|
||||
local name, value = pair:match("^%s*(.-)%s*=%s*(.-)%s*$")
|
||||
if name and value then
|
||||
cookies[name] = url_decode(value)
|
||||
end
|
||||
end
|
||||
return cookies
|
||||
end
|
||||
|
||||
function url_decode(str)
|
||||
str = str:gsub('%%(%x%x)', function(h)
|
||||
return string.char(tonumber(h, 16))
|
||||
end)
|
||||
return str
|
||||
end
|
||||
|
||||
|
||||
|
|
@ -1,11 +0,0 @@
|
|||
|
||||
function max(num1, num2)
|
||||
|
||||
if (num1 > num2) then
|
||||
result = num1;
|
||||
else
|
||||
result = num2;
|
||||
end
|
||||
|
||||
return result;
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue