mirror of
https://github.com/HoneyryderChuck/httpx.git
synced 2025-08-13 00:02:57 -04:00
testing log output, which allowed to remove a few more nocovs
This commit is contained in:
parent
6b7e233c84
commit
9955c2ba80
@ -140,9 +140,7 @@ module HTTPX
|
||||
headers[":authority"] = request.authority
|
||||
headers = headers.merge(request.headers)
|
||||
log(level: 1, label: "#{stream.id}: ", color: :yellow) do
|
||||
# :nocov:
|
||||
headers.map { |k, v| "-> HEADER: #{k}: #{v}" }.join("\n")
|
||||
# :nocov:
|
||||
end
|
||||
stream.headers(headers, end_stream: request.empty?)
|
||||
end
|
||||
@ -170,9 +168,7 @@ module HTTPX
|
||||
|
||||
def on_stream_headers(stream, request, h)
|
||||
log(label: "#{stream.id}:", color: :yellow) do
|
||||
# :nocov:
|
||||
h.map { |k, v| "<- HEADER: #{k}: #{v}" }.join("\n")
|
||||
# :nocov:
|
||||
end
|
||||
_, status = h.shift
|
||||
headers = request.options.headers_class.new(h)
|
||||
@ -237,28 +233,24 @@ module HTTPX
|
||||
def on_frame_sent(frame)
|
||||
log(level: 2, label: "#{frame[:stream]}: ") { "frame was sent!" }
|
||||
log(level: 2, label: "#{frame[:stream]}: ", color: :blue) do
|
||||
# :nocov:
|
||||
case frame[:type]
|
||||
when :data
|
||||
frame.merge(payload: frame[:payload].bytesize).inspect
|
||||
else
|
||||
frame.inspect
|
||||
end
|
||||
# :nocov
|
||||
end
|
||||
end
|
||||
|
||||
def on_frame_received(frame)
|
||||
log(level: 2, label: "#{frame[:stream]}: ") { "frame was received!" }
|
||||
log(level: 2, label: "#{frame[:stream]}: ", color: :magenta) do
|
||||
# :nocov:
|
||||
case frame[:type]
|
||||
when :data
|
||||
frame.merge(payload: frame[:payload].bytesize).inspect
|
||||
else
|
||||
frame.inspect
|
||||
end
|
||||
# :nocov:
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -4,13 +4,13 @@ require "openssl"
|
||||
|
||||
module HTTPX
|
||||
class SSL < TCP
|
||||
# :nocov:
|
||||
TLS_OPTIONS = if OpenSSL::SSL::SSLContext.instance_methods.include?(:alpn_protocols)
|
||||
{ alpn_protocols: %w[h2 http/1.1] }
|
||||
else
|
||||
# :nocov:
|
||||
{}
|
||||
# :nocov:
|
||||
end
|
||||
# :nocov:
|
||||
|
||||
def initialize(_, _, options)
|
||||
@ctx = OpenSSL::SSL::SSLContext.new
|
||||
@ -66,8 +66,8 @@ module HTTPX
|
||||
::IO::WaitWritable
|
||||
end
|
||||
|
||||
# :nocov:
|
||||
if RUBY_VERSION < "2.3"
|
||||
# :nocov:
|
||||
def read(*)
|
||||
super
|
||||
rescue ::IO::WaitWritable
|
||||
@ -79,6 +79,7 @@ module HTTPX
|
||||
rescue ::IO::WaitReadable
|
||||
0
|
||||
end
|
||||
# :nocov:
|
||||
else
|
||||
if OpenSSL::VERSION < "2.0.6"
|
||||
def read(size, buffer)
|
||||
@ -92,7 +93,6 @@ module HTTPX
|
||||
end
|
||||
end
|
||||
end
|
||||
# :nocov:
|
||||
|
||||
# :nocov:
|
||||
def inspect
|
||||
@ -114,7 +114,6 @@ module HTTPX
|
||||
do_transition(nextstate)
|
||||
end
|
||||
|
||||
# :nocov:
|
||||
def log_transition_state(nextstate)
|
||||
return super unless nextstate == :negotiated
|
||||
|
||||
@ -130,6 +129,5 @@ module HTTPX
|
||||
" issuer: #{server_cert.issuer}\n" \
|
||||
" SSL certificate verify ok."
|
||||
end
|
||||
# :nocov:
|
||||
end
|
||||
end
|
||||
|
@ -163,7 +163,6 @@ module HTTPX
|
||||
@state = nextstate
|
||||
end
|
||||
|
||||
# :nocov:
|
||||
def log_transition_state(nextstate)
|
||||
case nextstate
|
||||
when :connected
|
||||
@ -172,6 +171,5 @@ module HTTPX
|
||||
"#{@ip}:#{@port} #{@state} -> #{nextstate}"
|
||||
end
|
||||
end
|
||||
# :nocov:
|
||||
end
|
||||
end
|
||||
|
@ -25,6 +25,23 @@ class HTTPTest < Minitest::Test
|
||||
include Plugins::Retries
|
||||
include Plugins::Multipart
|
||||
|
||||
def test_verbose_log
|
||||
log = StringIO.new
|
||||
uri = build_uri("/get")
|
||||
response = HTTPX.get(uri, debug: log, debug_level: 2)
|
||||
verify_status(response, 200)
|
||||
log_output = log.string
|
||||
# assert request headers
|
||||
assert log_output.match(%r{HEADLINE: "GET .+ HTTP/1\.1"})
|
||||
assert log_output.match(%r{HEADER: Accept: */*})
|
||||
assert log_output.match(/HEADER: Host: \w+/)
|
||||
assert log_output.match(/HEADER: Connection: keep\-alive/)
|
||||
# assert response headers
|
||||
assert log_output.match(%r{HEADLINE: 200 HTTP/1\.1})
|
||||
assert log_output.match(/HEADER: content\-type: \w+/)
|
||||
assert log_output.match(/HEADER: content\-length: \d+/)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def origin(orig = httpbin)
|
||||
|
@ -41,6 +41,33 @@ class HTTPSTest < Minitest::Test
|
||||
end
|
||||
end if ENV.key?("HTTPBIN_COALESCING_HOST")
|
||||
|
||||
def test_verbose_log
|
||||
log = StringIO.new
|
||||
uri = build_uri("/get")
|
||||
response = HTTPX.get(uri, debug: log, debug_level: 2)
|
||||
verify_status(response, 200)
|
||||
log_output = log.string
|
||||
# assert tls output
|
||||
assert log_output.match(%r{SSL connection using TLSv\d+\.\d+ / \w+})
|
||||
assert log_output.match(/ALPN, server accepted to use h2/)
|
||||
assert log_output.match(/Server certificate:/)
|
||||
assert log_output.match(/ subject: .+/)
|
||||
assert log_output.match(/ start date: .+ UTC/)
|
||||
assert log_output.match(/ expire date: .+ UTC/)
|
||||
assert log_output.match(/ issuer: .+/)
|
||||
assert log_output.match(/ SSL certificate verify ok./)
|
||||
# assert request headers
|
||||
assert log_output.match(/HEADER: :scheme: https/)
|
||||
assert log_output.match(/HEADER: :method: GET/)
|
||||
assert log_output.match(/HEADER: :path: .+/)
|
||||
assert log_output.match(/HEADER: :authority: .+/)
|
||||
assert log_output.match(%r{HEADER: accept: */*})
|
||||
# assert response headers
|
||||
assert log_output.match(/HEADER: :status: 200/)
|
||||
assert log_output.match(/HEADER: content\-type: \w+/)
|
||||
assert log_output.match(/HEADER: content\-length: \d+/)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def origin(orig = httpbin)
|
||||
|
Loading…
x
Reference in New Issue
Block a user