diff options
author | Matthew Wild <mwild1@gmail.com> | 2009-01-08 02:02:35 +0000 |
---|---|---|
committer | Matthew Wild <mwild1@gmail.com> | 2009-01-08 02:02:35 +0000 |
commit | a3661957b69b0e5ab9ddbcb28e7a06b9c5a30d0e (patch) | |
tree | a88c9c3fa88083b68f327caec963617f305a898a /net/http.lua | |
parent | f5f551a91d086ff64bf0f499c6821e11bcaf43f0 (diff) | |
download | prosody-a3661957b69b0e5ab9ddbcb28e7a06b9c5a30d0e.tar.gz prosody-a3661957b69b0e5ab9ddbcb28e7a06b9c5a30d0e.zip |
Fix to prevent calling HTTP request callback twice with the same data
Diffstat (limited to 'net/http.lua')
-rw-r--r-- | net/http.lua | 9 |
1 files changed, 7 insertions, 2 deletions
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...") |