Skip to content

Commit ac68ee5

Browse files
authored
Merge pull request #39 from baweaver/baweaver/nit/d-method-alias-debug
Rename `D` to `debug` in `Net::HTTP`
2 parents 38d8a19 + 582d6e8 commit ac68ee5

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

lib/net/http.rb

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -993,7 +993,7 @@ def connect
993993
conn_port = port
994994
end
995995

996-
D "opening connection to #{conn_addr}:#{conn_port}..."
996+
debug "opening connection to #{conn_addr}:#{conn_port}..."
997997
begin
998998
s = Socket.tcp conn_addr, conn_port, @local_host, @local_port, connect_timeout: @open_timeout
999999
rescue => e
@@ -1002,7 +1002,7 @@ def connect
10021002
"#{conn_addr}:#{conn_port} (#{e.message})"
10031003
end
10041004
s.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
1005-
D "opened"
1005+
debug "opened"
10061006
if use_ssl?
10071007
if proxy?
10081008
plain_sock = BufferedIO.new(s, read_timeout: @read_timeout,
@@ -1036,7 +1036,7 @@ def connect
10361036
OpenSSL::SSL::SSLContext::SESSION_CACHE_CLIENT |
10371037
OpenSSL::SSL::SSLContext::SESSION_CACHE_NO_INTERNAL_STORE
10381038
@ssl_context.session_new_cb = proc {|sock, sess| @ssl_session = sess }
1039-
D "starting SSL for #{conn_addr}:#{conn_port}..."
1039+
debug "starting SSL for #{conn_addr}:#{conn_port}..."
10401040
s = OpenSSL::SSL::SSLSocket.new(s, @ssl_context)
10411041
s.sync_close = true
10421042
# Server Name Indication (SNI) RFC 3546
@@ -1049,7 +1049,7 @@ def connect
10491049
if (@ssl_context.verify_mode != OpenSSL::SSL::VERIFY_NONE) && @ssl_context.verify_hostname
10501050
s.post_connection_check(@address)
10511051
end
1052-
D "SSL established, protocol: #{s.ssl_version}, cipher: #{s.cipher[0]}"
1052+
debug "SSL established, protocol: #{s.ssl_version}, cipher: #{s.cipher[0]}"
10531053
end
10541054
@socket = BufferedIO.new(s, read_timeout: @read_timeout,
10551055
write_timeout: @write_timeout,
@@ -1059,7 +1059,7 @@ def connect
10591059
on_connect
10601060
rescue => exception
10611061
if s
1062-
D "Conn close because of connect error #{exception}"
1062+
debug "Conn close because of connect error #{exception}"
10631063
s.close
10641064
end
10651065
raise
@@ -1593,18 +1593,18 @@ def transport_request(req)
15931593
if count < max_retries && IDEMPOTENT_METHODS_.include?(req.method)
15941594
count += 1
15951595
@socket.close if @socket
1596-
D "Conn close because of error #{exception}, and retry"
1596+
debug "Conn close because of error #{exception}, and retry"
15971597
retry
15981598
end
1599-
D "Conn close because of error #{exception}"
1599+
debug "Conn close because of error #{exception}"
16001600
@socket.close if @socket
16011601
raise
16021602
end
16031603

16041604
end_transport req, res
16051605
res
16061606
rescue => exception
1607-
D "Conn close because of error #{exception}"
1607+
debug "Conn close because of error #{exception}"
16081608
@socket.close if @socket
16091609
raise exception
16101610
end
@@ -1614,11 +1614,11 @@ def begin_transport(req)
16141614
connect
16151615
elsif @last_communicated
16161616
if @last_communicated + @keep_alive_timeout < Process.clock_gettime(Process::CLOCK_MONOTONIC)
1617-
D 'Conn close because of keep_alive_timeout'
1617+
debug 'Conn close because of keep_alive_timeout'
16181618
@socket.close
16191619
connect
16201620
elsif @socket.io.to_io.wait_readable(0) && @socket.eof?
1621-
D "Conn close because of EOF"
1621+
debug "Conn close because of EOF"
16221622
@socket.close
16231623
connect
16241624
end
@@ -1636,15 +1636,15 @@ def end_transport(req, res)
16361636
@curr_http_version = res.http_version
16371637
@last_communicated = nil
16381638
if @socket.closed?
1639-
D 'Conn socket closed'
1639+
debug 'Conn socket closed'
16401640
elsif not res.body and @close_on_empty_response
1641-
D 'Conn close'
1641+
debug 'Conn close'
16421642
@socket.close
16431643
elsif keep_alive?(req, res)
1644-
D 'Conn keep-alive'
1644+
debug 'Conn keep-alive'
16451645
@last_communicated = Process.clock_gettime(Process::CLOCK_MONOTONIC)
16461646
else
1647-
D 'Conn close'
1647+
debug 'Conn close'
16481648
@socket.close
16491649
end
16501650
end
@@ -1699,11 +1699,14 @@ def addr_port
16991699
default_port == port ? addr : "#{addr}:#{port}"
17001700
end
17011701

1702-
def D(msg)
1702+
# Adds a message to debugging output
1703+
def debug(msg)
17031704
return unless @debug_output
17041705
@debug_output << msg
17051706
@debug_output << "\n"
17061707
end
1708+
1709+
alias_method :D, :debug
17071710
end
17081711

17091712
end

0 commit comments

Comments
 (0)