From 7148417dbb8ead54ab628d20da2ce70edd6dfb98 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 19 Feb 2010 03:21:20 +0000 Subject: net.http: Don't re-destroy a request when the connection is closed --- net/http.lua | 1 + 1 file changed, 1 insertion(+) (limited to 'net/http.lua') diff --git a/net/http.lua b/net/http.lua index a5acf46d..863efc6c 100644 --- a/net/http.lua +++ b/net/http.lua @@ -43,6 +43,7 @@ local function request_reader(request, data, startpos) elseif request.state ~= "completed" then -- Error.. connection was closed prematurely request.callback("connection-closed", 0, request); + return; end destroy_request(request); request.body = nil; -- cgit v1.2.3 From 463a83ee3fdf733f3d726874c8671f3f17a19ea0 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 19 Feb 2010 03:21:50 +0000 Subject: net.http: Close connection when invalid status line is received from the server --- net/http.lua | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'net/http.lua') diff --git a/net/http.lua b/net/http.lua index 863efc6c..b03b357c 100644 --- a/net/http.lua +++ b/net/http.lua @@ -107,7 +107,10 @@ local function request_reader(request, data, startpos) local http, code, text, linelen = data:match("^HTTP/(%S+) (%d+) (.-)\r\n()", startpos); code = tonumber(code); if not code then - return request.callback("invalid-status-line", 0, request); + log("warn", "Invalid HTTP status line, telling callback then closing"); + local ret = request.callback("invalid-status-line", 0, request); + destroy_request(request); + return ret; end request.code, request.responseversion = code, http; -- cgit v1.2.3 From 4936167a323b44c1768d6339a3fa32b448a96456 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 19 Feb 2010 03:22:42 +0000 Subject: net.http: destroy_request(): Remove update for new server API, pass request.handler instead of request.conn to ondisconnect --- net/http.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'net/http.lua') diff --git a/net/http.lua b/net/http.lua index b03b357c..f4a9da51 100644 --- a/net/http.lua +++ b/net/http.lua @@ -212,8 +212,9 @@ end function destroy_request(request) if request.conn then - request.handler.close() - listener.ondisconnect(request.conn, "closed"); + request.conn = nil; + request.handler:close() + listener.ondisconnect(request.handler, "closed"); end end -- cgit v1.2.3 From dd726b487bc989865d19942d49d9f86fcab9fcf8 Mon Sep 17 00:00:00 2001 From: Matthew Wild Date: Fri, 19 Feb 2010 03:27:18 +0000 Subject: net.http: Update print()s to log()s - don't ask how this came to be, I have no idea :) --- net/http.lua | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'net/http.lua') diff --git a/net/http.lua b/net/http.lua index f4a9da51..cd969209 100644 --- a/net/http.lua +++ b/net/http.lua @@ -17,11 +17,10 @@ local connlisteners_get = require "net.connlisteners".get; local listener = connlisteners_get("httpclient") or error("No httpclient listener!"); local t_insert, t_concat = table.insert, table.concat; -local tonumber, tostring, pairs, xpcall, select, debug_traceback, char, format = +local tonumber, tostring, pairs, xpcall, select, debug_traceback, char, format = tonumber, tostring, pairs, xpcall, select, debug.traceback, string.char, string.format; local log = require "util.logger".init("http"); -local print = function () end module "http" @@ -51,7 +50,7 @@ local function request_reader(request, data, startpos) return; end if request.state == "body" and request.state ~= "completed" then - print("Reading body...") + log("debug", "Reading body...") if not request.body then request.body = {}; request.havebodylength, request.bodylength = 0, tonumber(request.responseheaders["content-length"]); end if startpos then data = data:sub(startpos, -1) @@ -68,11 +67,11 @@ local function request_reader(request, data, startpos) request.body = nil; request.state = "completed"; else - print("", "Have "..request.havebodylength.." bytes out of "..request.bodylength); + log("debug", "Have "..request.havebodylength.." bytes out of "..request.bodylength); end end elseif request.state == "headers" then - print("Reading headers...") + log("debug", "Reading headers...") local pos = startpos; local headers, headers_complete = request.responseheaders; if not headers then @@ -84,12 +83,12 @@ local function request_reader(request, data, startpos) local k, v = line:match("(%S+): (.+)"); if k and v then headers[k:lower()] = v; - --print("Header: "..k:lower().." = "..v); + --log("debug", "Header: "..k:lower().." = "..v); elseif #line == 0 then headers_complete = true; break; else - print("Unhandled header line: "..line); + log("warn", "Unhandled header line: "..line); end end if not headers_complete then return; end @@ -103,7 +102,7 @@ local function request_reader(request, data, startpos) return request_reader(request, data, startpos); end elseif request.state == "status" then - print("Reading status...") + log("debug", "Reading status...") local http, code, text, linelen = data:match("^HTTP/(%S+) (%d+) (.-)\r\n()", startpos); code = tonumber(code); if not code then -- cgit v1.2.3