From 9cdc7bf8df3a418dc8f00191a49bdd3c94093af0 Mon Sep 17 00:00:00 2001 From: Kevin McPhillips Date: Thu, 2 Nov 2023 14:50:18 -0400 Subject: [PATCH] Only show proxy_port and proxy_address when Net::HTTP#proxy? is true --- lib/net/http/persistent.rb | 18 ++++++++++++++---- test/test_net_http_persistent.rb | 3 +++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/net/http/persistent.rb b/lib/net/http/persistent.rb index 5452fbb..46eefb1 100644 --- a/lib/net/http/persistent.rb +++ b/lib/net/http/persistent.rb @@ -612,13 +612,23 @@ def connection_for uri return yield connection rescue Errno::ECONNREFUSED - address = http.proxy_address || http.address - port = http.proxy_port || http.port + if http.proxy? + address = http.proxy_address + port = http.proxy_port + else + address = http.address + port = http.port + end raise Error, "connection refused: #{address}:#{port}" rescue Errno::EHOSTDOWN - address = http.proxy_address || http.address - port = http.proxy_port || http.port + if http.proxy? + address = http.proxy_address + port = http.proxy_port + else + address = http.address + port = http.port + end raise Error, "host down: #{address}:#{port}" ensure diff --git a/test/test_net_http_persistent.rb b/test/test_net_http_persistent.rb index 0f2bde2..fc90e90 100644 --- a/test/test_net_http_persistent.rb +++ b/test/test_net_http_persistent.rb @@ -116,6 +116,9 @@ def proxy_address end def proxy_port end + def proxy? + false + end end def basic_connection