Skip to content
This repository has been archived by the owner on Nov 20, 2018. It is now read-only.

Commit

Permalink
Resolved an issue with http session re-use.
Browse files Browse the repository at this point in the history
  • Loading branch information
trevorrowe committed Dec 3, 2014
1 parent e8df800 commit 2ebebf9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
Unreleased Changes
------------------

* Issue - Persistent Connections - Resolved an issue that prevented Aws::S3::Client
from re-using HTTP connections.

2.0.11 (2014-11-26)
------------------

Expand Down Expand Up @@ -383,7 +389,7 @@
See the client API documentation for `#wait_until` and the resource API
documentation for `#wait_until_{condition}`.

* Feature - Resources - Merged in resources branch. You can now use
* Feature - Resources - Merged in resources branch. You can now use
resource-oriented interfaces with `Aws::S3`, `Aws::EC2`, `Aws::SQS`,
`Aws::SNS`, `Aws::Glacier`,
and `Aws::IAM`.
Expand Down
15 changes: 12 additions & 3 deletions aws-sdk-core/lib/seahorse/client/net_http/connection_pool.rb
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@ def request(endpoint, request, &block)
end
end

# @param [URI::HTTP, URI::HTTPS, String] endpoint The HTTP(S) endpoint
# @param [URI::HTTP, URI::HTTPS] endpoint The HTTP(S) endpoint
# to connect to (e.g. 'https://domain.com').
#
# @yieldparam [Net::HTTPSession] session
#
# @return [nil]
def session_for(endpoint, &block)
endpoint = endpoint.to_s
endpoint = remove_path_and_query(endpoint)
session = nil

# attempt to recycle an already open session
Expand Down Expand Up @@ -151,13 +151,22 @@ def empty!
nil
end

private

def remove_path_and_query(endpoint)
endpoint.dup.tap do |e|
e.path = ''
e.query = nil
end.to_s
end

class << self

# Returns a connection pool constructed from the given options.
# Calling this method twice with the same options will return
# the same pool.
#
# @option options [URI::HTTP,String] :http_proxy A proxy to send
# @option options [URI::HTTP,String] :http_proxy A proxy to send
# requests through. Formatted like 'http://proxy.com:123'.
#
# @option options [Float] :http_open_timeout (15) The number of
Expand Down
22 changes: 22 additions & 0 deletions aws-sdk-core/spec/seahorse/client/net_http/handler_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'spec_helper'
require 'ostruct'
require 'stringio'
require 'uri'

module Seahorse
module Client
Expand All @@ -26,6 +27,27 @@ def endpoint
@endpoint ||= 'http://test.endpoint.api'
end

describe '#session_for' do

it 're-uses session for endpoints that share port, scheme and host' do
session = double('http-session', last_used: Time.now).as_null_object
pool = ConnectionPool.for({})
expect(pool).to receive(:start_session).
exactly(1).times.
with('http://foo.com').
and_return(session)
endpoint1 = URI.parse('http://foo.com/path?query')
endpoint2 = URI.parse('http://foo.com/different')
endpoint3 = URI.parse('http://foo.com')
sessions = []
pool.session_for(endpoint1) { |https| sessions << https }
pool.session_for(endpoint2) { |https| sessions << https }
pool.session_for(endpoint3) { |https| sessions << https }
expect(sessions).to eq([session, session, session])
end

end

describe '#pool' do

let(:handler_pool) { handler.pool_for(config) }
Expand Down

0 comments on commit 2ebebf9

Please sign in to comment.