allow debug option, which can be passed the logger (must respond to #<<); using it in the debug logger for http1 payload and http2 frames

This commit is contained in:
HoneyryderChuck 2017-12-13 01:23:38 +00:00
parent 1230f9e0fa
commit 89298be707
5 changed files with 14 additions and 8 deletions

View File

@ -147,8 +147,8 @@ module HTTPX
end
def log(&msg)
return unless $HTTPX_DEBUG
$stderr << (+"" << msg.call << "\n")
return unless @options.debug
@options.debug << (+"" << msg.call << "\n")
end
end
Channel.register "http/1.1", Channel::HTTP1

View File

@ -176,8 +176,8 @@ module HTTPX
end
def log(&msg)
return unless $HTTPX_DEBUG
$stderr << (+"connection (HTTP/2): " << msg.call << "\n")
return unless @options.debug
@options.debug << (+"connection (HTTP/2): " << msg.call << "\n")
end
end
Channel.register "h2", Channel::HTTP2

View File

@ -97,6 +97,10 @@ module HTTPX
!@keep_open && !@connected
end
def inspect
"#<#{self.class}#{@io.fileno}: #{@ip}:#{@port}>"
end
private
def build_socket
@ -105,8 +109,8 @@ module HTTPX
end
def log(&msg)
return unless $HTTPX_DEBUG
$stderr << (+"io: " << msg.call << "\n")
return unless @options.debug
@options.debug << (+"#{inspect}: " << msg.call << "\n")
end
end

View File

@ -41,6 +41,7 @@ module HTTPX
def initialize(options = {})
defaults = {
:debug => ENV.key?("HTTPX_DEBUG") ? $stderr : nil,
:proxy => {},
:ssl => { alpn_protocols: %w[h2 http/1.1] },
:fallback_protocol => "http/1.1",
@ -95,7 +96,7 @@ module HTTPX
params form json body
proxy follow ssl max_retries
request_class response_class headers_class response_body_class
io fallback_protocol
io fallback_protocol debug
].each do |method_name|
def_option(method_name)
end

View File

@ -57,7 +57,8 @@ class OptionsSpec < Minitest::Test
assert foo.merge(bar).to_hash == {
:io => nil,
:io => ENV.key?("HTTPX_DEBUG") ? $stderr : nil,
:debug => nil,
:params => nil,
:json => nil,
:body => nil,