diff options
author | Jo-Philipp Wich <jow@openwrt.org> | 2015-01-22 12:06:05 +0100 |
---|---|---|
committer | Jo-Philipp Wich <jow@openwrt.org> | 2015-01-22 12:06:05 +0100 |
commit | 4b2d2e3603e1a061d31e200622c7d71780b7c6a4 (patch) | |
tree | 9e6aac054dedd8b495249bcae0f3d5dbd2328450 | |
parent | 0d541a4cbdeb51ac23d4a1ce7bc561e1c0790c77 (diff) | |
parent | 3dbdff70960ec8c7de7d5a54721a560941627e0b (diff) |
Merge pull request #306 from Preffer/master
libs/luci-lib-httpclient: fix not straightforward behavior of httpclient
-rw-r--r-- | libs/luci-lib-httpclient/luasrc/httpclient.lua | 42 |
1 files changed, 26 insertions, 16 deletions
diff --git a/libs/luci-lib-httpclient/luasrc/httpclient.lua b/libs/luci-lib-httpclient/luasrc/httpclient.lua index 94c2e9ecac..c76cc542ed 100644 --- a/libs/luci-lib-httpclient/luasrc/httpclient.lua +++ b/libs/luci-lib-httpclient/luasrc/httpclient.lua @@ -97,7 +97,11 @@ end function request_raw(uri, options) options = options or {} 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 pr, auth, host, port, path = uri:match("(%w+)://(.+)@(%b[]):?([0-9]*)(.*)") @@ -176,20 +180,8 @@ function request_raw(uri, options) options.method = options.method or "POST" end - -- Assemble message - local message = {(options.method or "GET") .. " " .. path .. " " .. protocol} - - for k, v in pairs(headers) do - if type(v) == "string" or type(v) == "number" then - message[#message+1] = k .. ": " .. v - elseif type(v) == "table" then - for i, j in ipairs(v) do - message[#message+1] = k .. ": " .. j - end - 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 @@ -197,11 +189,29 @@ function request_raw(uri, options) 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 + 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 + local message = {(options.method or "GET") .. " " .. path .. " " .. protocol} + for k, v in pairs(headers) do + if type(v) == "string" or type(v) == "number" then + message[#message+1] = k .. ": " .. v + elseif type(v) == "table" then + for i, j in ipairs(v) do + message[#message+1] = k .. ": " .. j + end + end + end + message[#message+1] = "" message[#message+1] = "" @@ -323,7 +333,7 @@ function request_raw(uri, options) end end - return response.code, response, linesrc(true), sock + return response.code, response, linesrc(true)..sock:readall(), sock end function cookie_parse(cookiestr) |