From a3661957b69b0e5ab9ddbcb28e7a06b9c5a30d0e Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Thu, 8 Jan 2009 02:02:35 +0000 Subject: Fix to prevent calling HTTP request callback twice with the same data --- net/http.lua | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'net') diff --git a/net/http.lua b/net/http.lua index 38db0c0d..64d83948 100644 --- a/net/http.lua +++ b/net/http.lua @@ -27,8 +27,9 @@ end 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 @@ local function request_reader(request, data, startpos) 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...") -- cgit v1.2.3