mirror of
https://github.com/cloudwu/skynet.git
synced 2026-07-25 12:43:09 +00:00
bugfix, parsing http array form (#1852)
This commit is contained in:
@@ -20,7 +20,17 @@ end
|
|||||||
function url.parse_query(q)
|
function url.parse_query(q)
|
||||||
local r = {}
|
local r = {}
|
||||||
for k,v in q:gmatch "(.-)=([^&]*)&?" do
|
for k,v in q:gmatch "(.-)=([^&]*)&?" do
|
||||||
r[decode(k)] = decode(v)
|
local dk, dv = decode(k), decode(v)
|
||||||
|
local oldv = r[dk]
|
||||||
|
if oldv then
|
||||||
|
if type(oldv) ~= "table" then
|
||||||
|
r[dk] = {oldv, dv}
|
||||||
|
else
|
||||||
|
oldv[#oldv+1] = dv
|
||||||
|
end
|
||||||
|
else
|
||||||
|
r[dk] = dv
|
||||||
|
end
|
||||||
end
|
end
|
||||||
return r
|
return r
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
local skynet = require "skynet"
|
local skynet = require "skynet"
|
||||||
local httpc = require "http.httpc"
|
local httpc = require "http.httpc"
|
||||||
|
local httpurl = require "http.url"
|
||||||
local dns = require "skynet.dns"
|
local dns = require "skynet.dns"
|
||||||
|
|
||||||
local function http_test(protocol)
|
local function http_test(protocol)
|
||||||
@@ -44,11 +45,25 @@ local function http_head_test()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function http_url_test()
|
||||||
|
local url = "http://baidu.com/get?k1=1&k2=2&k4=a%20space&k5=b%20space&k5=b%20space&k5=b%20space"
|
||||||
|
local path, query = httpurl.parse(url)
|
||||||
|
print("url", path, query)
|
||||||
|
local qret = httpurl.parse_query(query)
|
||||||
|
for k, v in pairs(qret) do
|
||||||
|
print(k, v)
|
||||||
|
end
|
||||||
|
assert(#qret["k5"] == 3)
|
||||||
|
assert(qret[1] == qret[2])
|
||||||
|
assert(qret[1] == qret[3])
|
||||||
|
end
|
||||||
|
|
||||||
local function main()
|
local function main()
|
||||||
dns.server()
|
dns.server()
|
||||||
|
|
||||||
http_stream_test()
|
http_stream_test()
|
||||||
http_head_test()
|
http_head_test()
|
||||||
|
http_url_test()
|
||||||
|
|
||||||
http_test("http")
|
http_test("http")
|
||||||
if not pcall(require,"ltls.c") then
|
if not pcall(require,"ltls.c") then
|
||||||
|
|||||||
Reference in New Issue
Block a user