From 4b6cff1b8dae6b4b40faebe61be3074862bec189 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 12 Dec 2008 04:16:35 +0000 Subject: HTTP request callbacks now: handler(code, content) (where code may be 0, and content an error message) --- net/http.lua | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/net/http.lua b/net/http.lua index f51172c8..9a2249f2 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(t_concat(request.body)); + request.callback(request.code, t_concat(request.body)); else -- Error.. connection was closed prematurely - request.callback(nil, "connection-closed"); + request.callback(0, "connection-closed"); 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(t_concat(request.body)); + request.callback(request.code, t_concat(request.body)); end end print("", "Have "..request.havebodylength.." bytes out of "..request.bodylength); @@ -78,14 +78,14 @@ local function request_reader(request, data, startpos) print("Reading status...") local http, code, text, linelen = data:match("^HTTP/(%S+) (%d+) (.-)\r\n()", startpos); if not code then - return request.callback(nil, "invalid-status-line", data); + return request.callback(0, "invalid-status-line"); end request.responsecode, request.responseversion = code, http; if request.onlystatus or not expectbody(request, tonumber(code)) then if request.callback then - request.callback(code); + request.callback(code, nil); end destroy_request(request); return; -- cgit v1.2.3