Changeset 4313
- Timestamp:
- 03/09/09 15:02:34 (4 years ago)
- Files:
-
- 1 modified
-
luci/trunk/libs/httpclient/luasrc/httpclient.lua (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
luci/trunk/libs/httpclient/luasrc/httpclient.lua
r4286 r4313 23 23 24 24 local type, pairs, ipairs, tonumber = type, pairs, ipairs, tonumber 25 local unpack = unpack 25 26 26 27 module "luci.httpclient" … … 161 162 end 162 163 164 if type(options.body) == "function" then 165 options.method = options.method or "POST" 166 end 167 163 168 -- Assemble message 164 169 local message = {(options.method or "GET") .. " " .. path .. " " .. protocol} … … 195 200 if type(options.body) == "string" then 196 201 sock:sendall(options.body) 202 elseif type(options.body) == "function" then 203 local res = {options.body(sock)} 204 if not res[1] then 205 sock:close() 206 return unpack(res) 207 end 197 208 end 198 209 … … 202 213 203 214 if not line then 215 sock:close() 204 216 return nil, code, error 205 217 end 206 218 207 local protocol, status, msg = line:match("^( HTTP/[0-9.]+) ([0-9]+) (.*)")219 local protocol, status, msg = line:match("^([%w./]+) ([0-9]+) (.*)") 208 220 209 221 if not protocol then 222 sock:close() 210 223 return nil, -3, "invalid response magic: " .. line 211 224 end … … 229 242 230 243 if not line then 244 sock:close() 231 245 return nil, -4, "protocol error" 232 246 end
