Merge pull request #306 from Preffer/master
libs/luci-lib-httpclient: fix not straightforward behavior of httpclient
This commit is contained in:
commit
4b2d2e3603
1 changed files with 26 additions and 16 deletions
|
@ -98,6 +98,10 @@ function request_raw(uri, options)
|
||||||
options = options or {}
|
options = options or {}
|
||||||
local pr, auth, host, port, path
|
local pr, auth, host, port, path
|
||||||
|
|
||||||
|
if options.params then
|
||||||
|
uri = uri .. '?' .. http.urlencode_params(options.params)
|
||||||
|
end
|
||||||
|
|
||||||
if uri:find("%[") then
|
if uri:find("%[") then
|
||||||
if uri:find("@") then
|
if uri:find("@") then
|
||||||
pr, auth, host, port, path = uri:match("(%w+)://(.+)@(%b[]):?([0-9]*)(.*)")
|
pr, auth, host, port, path = uri:match("(%w+)://(.+)@(%b[]):?([0-9]*)(.*)")
|
||||||
|
@ -176,6 +180,25 @@ function request_raw(uri, options)
|
||||||
options.method = options.method or "POST"
|
options.method = options.method or "POST"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if options.cookies then
|
||||||
|
local cookiedata = {}
|
||||||
|
for _, c in ipairs(options.cookies) do
|
||||||
|
local cdo = c.flags.domain
|
||||||
|
local cpa = c.flags.path
|
||||||
|
if (cdo == host or cdo == "."..host or host:sub(-#cdo) == cdo)
|
||||||
|
and (cpa == path or cpa == "/" or cpa .. "/" == path:sub(#cpa+1))
|
||||||
|
and (not c.flags.secure or pr == "https")
|
||||||
|
then
|
||||||
|
cookiedata[#cookiedata+1] = c.key .. "=" .. c.value
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if headers["Cookie"] then
|
||||||
|
headers["Cookie"] = headers["Cookie"] .. "; " .. table.concat(cookiedata, "; ")
|
||||||
|
else
|
||||||
|
headers["Cookie"] = table.concat(cookiedata, "; ")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- Assemble message
|
-- Assemble message
|
||||||
local message = {(options.method or "GET") .. " " .. path .. " " .. protocol}
|
local message = {(options.method or "GET") .. " " .. path .. " " .. protocol}
|
||||||
|
|
||||||
|
@ -189,19 +212,6 @@ function request_raw(uri, options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
if options.cookies then
|
|
||||||
for _, c in ipairs(options.cookies) do
|
|
||||||
local cdo = c.flags.domain
|
|
||||||
local cpa = c.flags.path
|
|
||||||
if (cdo == host or cdo == "."..host or host:sub(-#cdo) == cdo)
|
|
||||||
and (cpa == path or cpa == "/" or cpa .. "/" == path:sub(#cpa+1))
|
|
||||||
and (not c.flags.secure or pr == "https")
|
|
||||||
then
|
|
||||||
message[#message+1] = "Cookie: " .. c.key .. "=" .. c.value
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
message[#message+1] = ""
|
message[#message+1] = ""
|
||||||
message[#message+1] = ""
|
message[#message+1] = ""
|
||||||
|
|
||||||
|
@ -323,7 +333,7 @@ function request_raw(uri, options)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
return response.code, response, linesrc(true), sock
|
return response.code, response, linesrc(true)..sock:readall(), sock
|
||||||
end
|
end
|
||||||
|
|
||||||
function cookie_parse(cookiestr)
|
function cookie_parse(cookiestr)
|
||||||
|
|
Loading…
Reference in a new issue