forked from rubygems/rubygems
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move Request::ConnectionPools::HTTPPool to Request
Also, its own file
- Loading branch information
Showing
4 changed files
with
48 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -238,5 +238,6 @@ def user_agent | |
|
||
end | ||
|
||
require 'rubygems/request/http_pool' | ||
require 'rubygems/request/connection_pools' | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|