Moved session.lua to http.lus and added Cookie-parser and URL-decoder functions.

This commit is contained in:
Johannes Findeisen 2024-05-19 08:03:36 +02:00
commit cf08430348
2 changed files with 29 additions and 11 deletions

29
lua/xw3/http.lua Normal file
View 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

View file

@ -1,11 +0,0 @@
function max(num1, num2)
if (num1 > num2) then
result = num1;
else
result = num2;
end
return result;
end