# HG changeset patch # User Matthew Wild # Date 1231380155 0 # Node ID 93e5309c54308cdf5b1d8dd888b21e3c8a61c207 # Parent 5e2dfeba1f14ec536b466240f72330b5d55517d8 Fix to prevent calling HTTP request callback twice with the same data diff -r 5e2dfeba1f14 -r 93e5309c5430 net/http.lua --- a/net/http.lua Wed Jan 07 17:41:27 2009 +0000 +++ b/net/http.lua Thu Jan 08 02:02:35 2009 +0000 @@ -27,8 +27,9 @@ local function request_reader(request, data, startpos) if not data then if request.body then + log("debug", "Connection closed, but we have data, calling callback..."); request.callback(t_concat(request.body), request.code, request); - else + elseif request.state ~= "completed" then -- Error.. connection was closed prematurely request.callback("connection-closed", 0, request); end @@ -46,11 +47,15 @@ request.havebodylength = request.havebodylength + #data; if request.havebodylength >= request.bodylength then -- We have the body + log("debug", "Have full body, calling callback"); if request.callback then request.callback(t_concat(request.body), request.code, request); end + request.body = nil; + request.state = "completed"; + else + print("", "Have "..request.havebodylength.." bytes out of "..request.bodylength); end - print("", "Have "..request.havebodylength.." bytes out of "..request.bodylength); end elseif request.state == "headers" then print("Reading headers...")