method
connection_for
v2_6_3 -
Show latest stable
- Class:
Bundler::Persistent::Net::HTTP::Persistent
connection_for(uri)public
Creates a new connection for uri
# File lib/bundler/vendor/net-http-persistent/lib/net/http/persistent.rb, line 588
def connection_for uri
Thread.current[@generation_key] ||= Hash.new { |h,k| h[k] = {} }
Thread.current[@ssl_generation_key] ||= Hash.new { |h,k| h[k] = {} }
Thread.current[@request_key] ||= Hash.new 0
Thread.current[@timeout_key] ||= Hash.new EPOCH
use_ssl = uri.scheme.downcase == 'https'
if use_ssl then
raise Bundler::Persistent::Net::HTTP::Persistent::Error, 'OpenSSL is not available' unless
HAVE_OPENSSL
ssl_generation = @ssl_generation
ssl_cleanup ssl_generation
connections = Thread.current[@ssl_generation_key][ssl_generation]
else
generation = @generation
cleanup generation
connections = Thread.current[@generation_key][generation]
end
net_http_args = [uri.host, uri.port]
connection_id = net_http_args.join ':'
if @proxy_uri and not proxy_bypass? uri.host, uri.port then
connection_id << @proxy_connection_id
net_http_args.concat @proxy_args
else
net_http_args.concat [nil, nil, nil, nil]
end
connection = connections[connection_id]
unless connection = connections[connection_id] then
connections[connection_id] = http_class.new(*net_http_args)
connection = connections[connection_id]
ssl connection if use_ssl
else
reset connection if expired? connection
end
start connection unless connection.started?
connection.read_timeout = @read_timeout if @read_timeout
connection.keep_alive_timeout = @idle_timeout if @idle_timeout && connection.respond_to?(:keep_alive_timeout=)
connection
rescue Errno::ECONNREFUSED
address = connection.proxy_address || connection.address
port = connection.proxy_port || connection.port
raise Error, "connection refused: #{address}:#{port}"
rescue Errno::EHOSTDOWN
address = connection.proxy_address || connection.address
port = connection.proxy_port || connection.port
raise Error, "host down: #{address}:#{port}"
end Related methods
- Instance methods
- ca_file=
- can_retry?
- cert=
- cert_store=
- certificate=
- cleanup
- connection_close?
- connection_for
- connection_keep_alive?
- error_message
- escape
- expired?
- finish
- http_class
- http_version
- idempotent?
- key=
- max_age
- normalize_uri
- pipeline
- private_key=
- proxy=
- proxy_bypass?
- proxy_from_env
- reconnect
- reconnect_ssl
- request
- request_failed
- request_setup
- reset
- shutdown
- shutdown_in_all_threads
- ssl
- ssl_cleanup
- ssl_version=
- start
- unescape
- verify_callback=
- verify_mode=
- Class methods
- detect_idle_timeout
- new