mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-09-01 00:00:35 -04:00
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:
parent
1230f9e0fa
commit
89298be707
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
x
Reference in New Issue
Block a user