Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

connection hooks cleanup #186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 6 additions & 19 deletions lib/net/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1626,23 +1626,20 @@ def peer_cert
#
def start # :yield: http
raise IOError, 'HTTP session already opened' if @started

@started = true
connect

if block_given?
begin
do_start
return yield(self)
ensure
do_finish
finish
end
end
do_start
self
end

def do_start
connect
@started = true
self
end
private :do_start

def connect
if use_ssl?
Expand Down Expand Up @@ -1750,7 +1747,6 @@ def connect
continue_timeout: @continue_timeout,
debug_output: @debug_output)
@last_communicated = nil
on_connect
rescue => exception
if s
debug "Conn close because of connect error #{exception}"
Expand All @@ -1760,10 +1756,6 @@ def connect
end
private :connect

def on_connect
end
private :on_connect

# Finishes the \HTTP session:
#
# http = Net::HTTP.new(hostname)
Expand All @@ -1775,15 +1767,10 @@ def on_connect
# Raises IOError if not in a session.
def finish
raise IOError, 'HTTP session not yet started' unless started?
do_finish
end

def do_finish
@started = false
@socket.close if @socket
@socket = nil
end
private :do_finish

#
# proxy
Expand Down