local date = require "luci.http.protocol.date"
local type, pairs, ipairs, tonumber = type, pairs, ipairs, tonumber
+local unpack = unpack
module "luci.httpclient"
options.method = options.method or "POST"
end
+ if type(options.body) == "function" then
+ options.method = options.method or "POST"
+ end
+
-- Assemble message
local message = {(options.method or "GET") .. " " .. path .. " " .. protocol}
if type(options.body) == "string" then
sock:sendall(options.body)
+ elseif type(options.body) == "function" then
+ local res = {options.body(sock)}
+ if not res[1] then
+ sock:close()
+ return unpack(res)
+ end
end
-- Create source and fetch response
local line, code, error = linesrc()
if not line then
+ sock:close()
return nil, code, error
end
- local protocol, status, msg = line:match("^(HTTP/[0-9.]+) ([0-9]+) (.*)")
+ local protocol, status, msg = line:match("^([%w./]+) ([0-9]+) (.*)")
if not protocol then
+ sock:close()
return nil, -3, "invalid response magic: " .. line
end
end
if not line then
+ sock:close()
return nil, -4, "protocol error"
end