mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-24 20:23:06 +00:00
simple url parser
This commit is contained in:
28
lualib/http/url.lua
Normal file
28
lualib/http/url.lua
Normal file
@@ -0,0 +1,28 @@
|
||||
local url = {}
|
||||
|
||||
local function decode_func(c)
|
||||
return string.char(tonumber(c, 16))
|
||||
end
|
||||
|
||||
local function decode(str)
|
||||
local str = str:gsub('+', ' ')
|
||||
return str:gsub("%%(..)", decode_func)
|
||||
end
|
||||
|
||||
function url.parse(u)
|
||||
local path,query = u:match "([^?]*)%??(.*)"
|
||||
if path then
|
||||
path = decode(path)
|
||||
end
|
||||
return path, query
|
||||
end
|
||||
|
||||
function url.parse_query(q)
|
||||
local r = {}
|
||||
for k,v in q:gmatch "(.-)=([^&]*)&?" do
|
||||
r[decode(k)] = decode(v)
|
||||
end
|
||||
return r
|
||||
end
|
||||
|
||||
return url
|
||||
Reference in New Issue
Block a user