Skip to content

Commit

Permalink
Move Request::ConnectionPools::HTTPPool to Request
Browse files Browse the repository at this point in the history
Also, its own file
  • Loading branch information
drbrain committed Apr 1, 2014
1 parent aa14f9c commit 88fc8e3
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 39 deletions.
7 changes: 7 additions & 0 deletions Manifest.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.autotest
.document
CONTRIBUTING
CVE-2013-4287.txt
CVE-2013-4363.txt
History.txt
Expand All @@ -11,6 +12,7 @@ Rakefile
UPGRADING.rdoc
bin/gem
bin/update_rubygems
fake.gemspec
hide_lib_for_update/note.txt
lib/gauntlet_rubygems.rb
lib/rubygems.rb
Expand All @@ -32,6 +34,7 @@ lib/rubygems/commands/install_command.rb
lib/rubygems/commands/list_command.rb
lib/rubygems/commands/lock_command.rb
lib/rubygems/commands/mirror_command.rb
lib/rubygems/commands/open_command.rb
lib/rubygems/commands/outdated_command.rb
lib/rubygems/commands/owner_command.rb
lib/rubygems/commands/pristine_command.rb
Expand Down Expand Up @@ -98,6 +101,8 @@ lib/rubygems/psych_tree.rb
lib/rubygems/rdoc.rb
lib/rubygems/remote_fetcher.rb
lib/rubygems/request.rb
lib/rubygems/request/connection_pools.rb
lib/rubygems/request/http_pool.rb
lib/rubygems/request_set.rb
lib/rubygems/request_set/gem_dependency_api.rb
lib/rubygems/request_set/lockfile.rb
Expand Down Expand Up @@ -235,6 +240,7 @@ test/rubygems/test_gem_commands_install_command.rb
test/rubygems/test_gem_commands_list_command.rb
test/rubygems/test_gem_commands_lock_command.rb
test/rubygems/test_gem_commands_mirror.rb
test/rubygems/test_gem_commands_open_command.rb
test/rubygems/test_gem_commands_outdated_command.rb
test/rubygems/test_gem_commands_owner_command.rb
test/rubygems/test_gem_commands_pristine_command.rb
Expand Down Expand Up @@ -282,6 +288,7 @@ test/rubygems/test_gem_platform.rb
test/rubygems/test_gem_rdoc.rb
test/rubygems/test_gem_remote_fetcher.rb
test/rubygems/test_gem_request.rb
test/rubygems/test_gem_request_connection_pool.rb
test/rubygems/test_gem_request_set.rb
test/rubygems/test_gem_request_set_gem_dependency_api.rb
test/rubygems/test_gem_request_set_lockfile.rb
Expand Down
1 change: 1 addition & 0 deletions lib/rubygems/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,6 @@ def user_agent

end

require 'rubygems/request/http_pool'
require 'rubygems/request/connection_pools'

41 changes: 2 additions & 39 deletions lib/rubygems/request/connection_pools.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,49 +23,12 @@ def pool_for uri
if https? uri then
Gem::Request::ConnectionPools::HTTPSPool.new(http_args, @cert_files, @proxy_uri)
else
Gem::Request::ConnectionPools::HTTPPool.new(http_args, @cert_files, @proxy_uri)
Gem::Request::HTTPPool.new(http_args, @cert_files, @proxy_uri)
end
end
end

###
# A connection "pool" that only manages one connection for now. Provides
# thread safe `checkout` and `checkin` methods. The pool consists of one
# connection that corresponds to `http_args`. This class is private, do not
# use it.

class HTTPPool # :nodoc:
attr_reader :cert_files, :proxy_uri

def initialize http_args, cert_files, proxy_uri
@http_args = http_args
@cert_files = cert_files
@proxy_uri = proxy_uri
@queue = SizedQueue.new 1
@queue << nil
end

def checkout
@queue.pop || make_connection
end

def checkin connection
@queue.push connection
end

private

def make_connection
setup_connection Gem::Request::ConnectionPools.client.new(*@http_args)
end

def setup_connection connection
connection.start
connection
end
end

class HTTPSPool < HTTPPool # :nodoc:
class HTTPSPool < Gem::Request::HTTPPool # :nodoc:
private

def setup_connection connection
Expand Down
38 changes: 38 additions & 0 deletions lib/rubygems/request/http_pool.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
##
# A connection "pool" that only manages one connection for now. Provides
# thread safe `checkout` and `checkin` methods. The pool consists of one
# connection that corresponds to `http_args`. This class is private, do not
# use it.

class Gem::Request::HTTPPool # :nodoc:
attr_reader :cert_files, :proxy_uri

def initialize http_args, cert_files, proxy_uri
@http_args = http_args
@cert_files = cert_files
@proxy_uri = proxy_uri
@queue = SizedQueue.new 1
@queue << nil
end

def checkout
@queue.pop || make_connection
end

def checkin connection
@queue.push connection
end

private

def make_connection
setup_connection Gem::Request::ConnectionPools.client.new(*@http_args)
end

def setup_connection connection
connection.start
connection
end

end

0 comments on commit 88fc8e3

Please sign in to comment.