From cabcee1bd056e34acb1e27c361e9f5b56af740ec Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 25 Dec 2008 03:05:06 +0000 Subject: 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 --- net/http.lua | 15 ++++++++------- 1 file 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; -- cgit v1.2.3