Comparison

net/http.lua @ 4471:ea24d73e6c94

net.http: Pass response object to callbacks (feels hacky, should this be passed *instead of* the request?)
author Matthew Wild <mwild1@gmail.com>
date Tue, 17 Jan 2012 00:30:52 +0000
parent 4369:3578ff5d3674
child 4557:2abe4e541d52
comparison
equal deleted inserted replaced
4470:0209bd5c4259 4471:ea24d73e6c94
68 if not request.parser then 68 if not request.parser then
69 if not data then return; end 69 if not data then return; end
70 local function success_cb(r) 70 local function success_cb(r)
71 if request.callback then 71 if request.callback then
72 for k,v in pairs(r) do request[k] = v; end 72 for k,v in pairs(r) do request[k] = v; end
73 request.callback(r.body, r.code, request); 73 request.callback(r.body, r.code, request, r);
74 request.callback = nil; 74 request.callback = nil;
75 end 75 end
76 destroy_request(request); 76 destroy_request(request);
77 end 77 end
78 local function error_cb(r) 78 local function error_cb(r)
146 end 146 end
147 147
148 req.handler, req.conn = server.wrapclient(conn, req.host, port, listener, "*a", using_https and { mode = "client", protocol = "sslv23" }); 148 req.handler, req.conn = server.wrapclient(conn, req.host, port, listener, "*a", using_https and { mode = "client", protocol = "sslv23" });
149 req.write = function (...) return req.handler:write(...); end 149 req.write = function (...) return req.handler:write(...); end
150 150
151 req.callback = function (content, code, request) log("debug", "Calling callback, status %s", code or "---"); return select(2, xpcall(function () return callback(content, code, request) end, handleerr)); end 151 req.callback = function (content, code, request, response) log("debug", "Calling callback, status %s", code or "---"); return select(2, xpcall(function () return callback(content, code, request, response) end, handleerr)); end
152 req.reader = request_reader; 152 req.reader = request_reader;
153 req.state = "status"; 153 req.state = "status";
154 154
155 listener.register_request(req.handler, req); 155 listener.register_request(req.handler, req);
156 156