Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toggle-able debugging #69

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions http/connection_common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add off

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
Expand Down
25 changes: 25 additions & 0 deletions http/h2_connection.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -387,13 +393,32 @@ 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

-- If this times out, it was the flushing; not the write itself
-- 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
Expand Down