Skip to content

Commit

Permalink
Restore Session#open signature for webmock compat
Browse files Browse the repository at this point in the history
TODO: create PR for webmock's httpclient adapter to use get_session
instead of open so that we can remove duplicated Site creation for
each session.
  • Loading branch information
Hiroshi Nakamura committed Nov 4, 2014
1 parent c44dcc4 commit 1cba7bf
Showing 1 changed file with 26 additions and 18 deletions.
44 changes: 26 additions & 18 deletions lib/httpclient/session.rb
Expand Up @@ -159,7 +159,7 @@ def proxy=(proxy)

def query(req, via_proxy)
req.http_body.chunk_size = @chunk_size if req.http_body
sess = open(req, via_proxy)
sess = get_session(req, via_proxy)
begin
sess.query(req)
rescue
Expand Down Expand Up @@ -195,30 +195,38 @@ def invalidate(site)

private

def open(req, via_proxy = false)
# TODO: create PR for webmock's httpclient adapter to use get_session
# instead of open so that we can remove duplicated Site creation for
# each session.
def get_session(req, via_proxy = false)
site = Site.new(req.header.request_uri)
if req.use_persistent_connection? && cached = get_cached_session(site)
cached
else
sess = Session.new(@client, site, @agent_name, @from)
sess.proxy = via_proxy ? @proxy : nil
sess.socket_sync = @socket_sync
sess.requested_version = @protocol_version if @protocol_version
sess.connect_timeout = @connect_timeout
sess.connect_retry = @connect_retry
sess.send_timeout = @send_timeout
sess.receive_timeout = @receive_timeout
sess.read_block_size = @read_block_size
sess.protocol_retry_count = @protocol_retry_count
sess.ssl_config = @ssl_config
sess.debug_dev = @debug_dev
sess.socket_local = @socket_local
sess.test_loopback_http_response = @test_loopback_http_response
sess.transparent_gzip_decompression = @transparent_gzip_decompression
sess
open(req.header.request_uri, via_proxy)
end
end

def open(uri, via_proxy = false)
site = Site.new(uri)
sess = Session.new(@client, site, @agent_name, @from)
sess.proxy = via_proxy ? @proxy : nil
sess.socket_sync = @socket_sync
sess.requested_version = @protocol_version if @protocol_version
sess.connect_timeout = @connect_timeout
sess.connect_retry = @connect_retry
sess.send_timeout = @send_timeout
sess.receive_timeout = @receive_timeout
sess.read_block_size = @read_block_size
sess.protocol_retry_count = @protocol_retry_count
sess.ssl_config = @ssl_config
sess.debug_dev = @debug_dev
sess.socket_local = @socket_local
sess.test_loopback_http_response = @test_loopback_http_response
sess.transparent_gzip_decompression = @transparent_gzip_decompression
sess
end

def close_all
@sess_pool_mutex.synchronize do
@sess_pool.each do |site, pool|
Expand Down

4 comments on commit 1cba7bf

@bblimke
Copy link

@bblimke bblimke commented on 1cba7bf Nov 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LOL I just merged this one bblimke/webmock#430 :) //cc @godfat

@bblimke
Copy link

@bblimke bblimke commented on 1cba7bf Nov 5, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll remove @godfat patch in that case. @godfat thank you anyway :)

@godfat
Copy link

@godfat godfat commented on 1cba7bf Nov 6, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is great! :D
I hesitated to write it that way because it's really ugly,
but I really wanted to make it work immediately.
Now I just need to update httpclient again :)
Thanks for both of you.

@nahi
Copy link
Owner

@nahi nahi commented on 1cba7bf Nov 8, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@godfat My fault that I didn't run webmock spec. Thank YOU.

Please sign in to comment.