Skip to content

Commit 12a9230

Browse files
authored
Merge pull request drbrain#146 from kmcphillips/master
Show correct port and address in connection exception messages
2 parents c1fb1a5 + 9cdc7bf commit 12a9230

File tree

2 files changed

+17
-4
lines changed

2 files changed

+17
-4
lines changed

lib/net/http/persistent.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -612,13 +612,23 @@ def connection_for uri
612612

613613
return yield connection
614614
rescue Errno::ECONNREFUSED
615-
address = http.proxy_address || http.address
616-
port = http.proxy_port || http.port
615+
if http.proxy?
616+
address = http.proxy_address
617+
port = http.proxy_port
618+
else
619+
address = http.address
620+
port = http.port
621+
end
617622

618623
raise Error, "connection refused: #{address}:#{port}"
619624
rescue Errno::EHOSTDOWN
620-
address = http.proxy_address || http.address
621-
port = http.proxy_port || http.port
625+
if http.proxy?
626+
address = http.proxy_address
627+
port = http.proxy_port
628+
else
629+
address = http.address
630+
port = http.port
631+
end
622632

623633
raise Error, "host down: #{address}:#{port}"
624634
ensure

test/test_net_http_persistent.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ def proxy_address
116116
end
117117
def proxy_port
118118
end
119+
def proxy?
120+
false
121+
end
119122
end
120123

121124
def basic_connection

0 commit comments

Comments
 (0)