aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorMatthew Wild <mwild1@gmail.com>2008-12-25 03:05:06 +0000
committerMatthew Wild <mwild1@gmail.com>2008-12-25 03:05:06 +0000
commitcabcee1bd056e34acb1e27c361e9f5b56af740ec (patch)
treebfaa243aff6d90e036d12a43a81b654904851157 /net
parent2c5c16488981c16ae5655d3ae3ddb89966c1ce20 (diff)
downloadprosody-cabcee1bd056e34acb1e27c361e9f5b56af740ec.tar.gz
prosody-cabcee1bd056e34acb1e27c361e9f5b56af740ec.zip
HTTP requests now have status code as a number instead of a string. Switched parameters on both http.request() and the callback to better match LuaSocket's http module
Diffstat (limited to 'net')
-rw-r--r--net/http.lua15
1 files changed, 8 insertions, 7 deletions
diff --git a/net/http.lua b/net/http.lua
index 00949901..38db0c0d 100644
--- a/net/http.lua
+++ b/net/http.lua
@@ -27,10 +27,10 @@ end
local function request_reader(request, data, startpos)
if not data then
if request.body then
- request.callback(request.code, t_concat(request.body), request);
+ request.callback(t_concat(request.body), request.code, request);
else
-- Error.. connection was closed prematurely
- request.callback(0, "connection-closed", request);
+ request.callback("connection-closed", 0, request);
end
destroy_request(request);
return;
@@ -47,7 +47,7 @@ local function request_reader(request, data, startpos)
if request.havebodylength >= request.bodylength then
-- We have the body
if request.callback then
- request.callback(request.code, t_concat(request.body), request);
+ request.callback(t_concat(request.body), request.code, request);
end
end
print("", "Have "..request.havebodylength.." bytes out of "..request.bodylength);
@@ -77,15 +77,16 @@ local function request_reader(request, data, startpos)
elseif request.state == "status" then
print("Reading status...")
local http, code, text, linelen = data:match("^HTTP/(%S+) (%d+) (.-)\r\n()", startpos);
+ code = tonumber(code);
if not code then
- return request.callback(0, "invalid-status-line", request);
+ return request.callback("invalid-status-line", 0, request);
end
request.code, request.responseversion = code, http;
- if request.onlystatus or not expectbody(request, tonumber(code)) then
+ if request.onlystatus or not expectbody(request, code) then
if request.callback then
- request.callback(code, nil, request);
+ request.callback(nil, code, request);
end
destroy_request(request);
return;
@@ -99,7 +100,7 @@ local function request_reader(request, data, startpos)
end
end
-function request(u, callback, ex)
+function request(u, ex, callback)
local req = url.parse(u);
local custom_headers, body;