From 407899404dbf9decc8be2cf5e7acf5b1aec05f93 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 23 Jan 2017 19:16:57 +1100 Subject: [PATCH 1/2] http/h2_connection: Add some (optional) debugging calls --- http/h2_connection.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/http/h2_connection.lua b/http/h2_connection.lua index e1f445bb..144ffa01 100644 --- a/http/h2_connection.lua +++ b/http/h2_connection.lua @@ -160,6 +160,12 @@ local function new_connection(socket, conn_type, settings) socket:setvbuf("full", math.huge) -- 'infinite' buffering; no write locks needed socket:setmode("b", "bna") -- writes that don't explicitly buffer will now flush the buffer. autoflush on socket:onerror(onerror) + if self.debug then + self.debug(string.format("h2_connection.new(socket=%s, type=%s, ...) = %s\n", + tostring(socket), + conn_type, + tostring(self))) + end if self.type == "client" then assert(socket:xwrite(preface, "f", 0)) end @@ -387,6 +393,15 @@ function connection_methods:read_http2_frame(timeout) end -- reserved bit MUST be ignored by receivers streamid = band(streamid, 0x7fffffff) + if self.debug then + self.debug(string.format("h2_connection.read_http2_frame(self=%s, timeout=%f) = type=%s, flags=%d, streamid=%d, #payload=%d\n", + tostring(self), + timeout or math.huge, + h2_stream.frame_types[typ] or tostring(typ), + flags, + streamid, + #payload)) + end return typ, flags, streamid, payload end @@ -394,6 +409,16 @@ end -- hence it's not always total failure. -- It's up to the caller to take some action (e.g. closing) rather than doing it here function connection_methods:write_http2_frame(typ, flags, streamid, payload, timeout, flush) + if self.debug then + self.debug(string.format("h2_connection.write_http2_frame(self=%s, type=%s, flags=%d, streamid=%d, #payload=%d, timeout=%f, flush=%q)\n", + tostring(self), + h2_stream.frame_types[typ] or tostring(typ), + flags, + streamid, + #payload, + timeout or math.huge, + flush or "")) + end if #payload > self.peer_settings[known_settings.MAX_FRAME_SIZE] then return nil, h2_error.errors.FRAME_SIZE_ERROR:new_traceback("frame too large"), ce.E2BIG end From 4d716b54eb7c59a32b1d7025c136b8008bb750c9 Mon Sep 17 00:00:00 2001 From: daurnimator Date: Mon, 23 Jan 2017 19:36:00 +1100 Subject: [PATCH 2/2] http/connection_common: Initialise connection.debug from environmental variable --- http/connection_common.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/http/connection_common.lua b/http/connection_common.lua index 432acfe4..cf0267bb 100644 --- a/http/connection_common.lua +++ b/http/connection_common.lua @@ -4,6 +4,16 @@ local ce = require "cqueues.errno" local connection_methods = {} +local function positive(x) + return x ~= nil and x ~= "0" and x:lower() ~= "false" and x:lower() ~= "no" +end + +if positive(os.getenv "LUA_HTTP_DEBUG") then + function connection_methods.debug(...) + io.stderr:write(...) + end +end + local function onerror(socket, op, why, lvl) -- luacheck: ignore 212 local err = string.format("%s: %s", op, ce.strerror(why)) if op == "starttls" then