# HG changeset patch # User Matthew Wild # Date 1229056235 0 # Node ID 69de678792d6968285e1c0d85dd42eea11e76622 # Parent b17fd66b7e10e12c66bcadc96a5f6215a0e82f36 Pass HTTP request object to callback diff -r b17fd66b7e10 -r 69de678792d6 net/http.lua --- a/net/http.lua Fri Dec 12 04:16:35 2008 +0000 +++ b/net/http.lua Fri Dec 12 04:30:35 2008 +0000 @@ -27,10 +27,10 @@ local function request_reader(request, data, startpos) if not data then if request.body then - request.callback(request.code, t_concat(request.body)); + request.callback(request.code, t_concat(request.body), request); else -- Error.. connection was closed prematurely - request.callback(0, "connection-closed"); + request.callback(0, "connection-closed", request); end destroy_request(request); return; @@ -47,7 +47,7 @@ if request.havebodylength >= request.bodylength then -- We have the body if request.callback then - request.callback(request.code, t_concat(request.body)); + request.callback(request.code, t_concat(request.body), request); end end print("", "Have "..request.havebodylength.." bytes out of "..request.bodylength); @@ -78,14 +78,14 @@ print("Reading status...") local http, code, text, linelen = data:match("^HTTP/(%S+) (%d+) (.-)\r\n()", startpos); if not code then - return request.callback(0, "invalid-status-line"); + return request.callback(0, "invalid-status-line", request); end request.responsecode, request.responseversion = code, http; if request.onlystatus or not expectbody(request, tonumber(code)) then if request.callback then - request.callback(code, nil); + request.callback(code, nil, request); end destroy_request(request); return;