Class: Net::HTTP::ConnectionPool::Connection
- Inherits:
-
Object
- Object
- Net::HTTP::ConnectionPool::Connection
- Defined in:
- lib/net/http/connection_pool/connection.rb
Overview
A light wrapper around Net::HTTP.
You should not need to construct connection objects yourself.
You receive them as a response to #connection_for.
Instance Attribute Summary collapse
- #host ⇒ String readonly
- #pool ⇒ ConnectionPool readonly
- #port ⇒ Integer readonly
- #proxy_address ⇒ String? readonly
- #proxy_password ⇒ String? readonly
- #proxy_port ⇒ Integer? readonly
- #proxy_user ⇒ String? readonly
- #read_timeout ⇒ Numeric?
- #ssl ⇒ Boolean readonly
- #ssl_ca_file ⇒ String? readonly
- #ssl_ca_path ⇒ String? readonly
- #ssl_verify_peer ⇒ Boolean readonly
Instance Method Summary collapse
- #initialize(pool, host, options = {}) ⇒ Connection constructor
-
#key ⇒ String
Returns a key that can be used to group connections that connection to the same host.
-
#proxy? ⇒ Boolean
Returns true if this connection proxies requests.
- #request(*args, &block) ⇒ Object
-
#ssl? ⇒ Boolean
Returns true if this connection requires SSL.
-
#ssl_verify_peer? ⇒ Boolean
Returns true if ssl connections should verify the peer certificate.
Constructor Details
#initialize(pool, host, options = {}) ⇒ Connection
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/net/http/connection_pool/connection.rb', line 29 def initialize pool, host, = {} @pool = pool @host = host @port = .key?(:port) ? [:port] : ([:ssl] ? 443 : 80) @ssl = .key?(:ssl) ? [:ssl] : (port == 443) @ssl_verify_peer = .key?(:ssl_verify_peer) ? [:ssl_verify_peer] : true @ssl_ca_file = [:ssl_ca_file] @ssl_ca_path = [:ssl_ca_path] if uri = [:proxy_uri] uri = URI.parse(uri) if uri.is_a?(String) @proxy_address = uri.host @proxy_port = uri.port @proxy_user = uri.user @proxy_password = uri.password else @proxy_address = [:proxy_address] @proxy_port = [:proxy_port] @proxy_user = [:proxy_user] @proxy_password = [:proxy_password] end @read_timeout = [:read_timeout] || 60 end |
Instance Attribute Details
#host ⇒ String (readonly)
67 68 69 |
# File 'lib/net/http/connection_pool/connection.rb', line 67 def host @host end |
#pool ⇒ ConnectionPool (readonly)
64 65 66 |
# File 'lib/net/http/connection_pool/connection.rb', line 64 def pool @pool end |
#port ⇒ Integer (readonly)
70 71 72 |
# File 'lib/net/http/connection_pool/connection.rb', line 70 def port @port end |
#proxy_address ⇒ String? (readonly)
85 86 87 |
# File 'lib/net/http/connection_pool/connection.rb', line 85 def proxy_address @proxy_address end |
#proxy_password ⇒ String? (readonly)
94 95 96 |
# File 'lib/net/http/connection_pool/connection.rb', line 94 def proxy_password @proxy_password end |
#proxy_port ⇒ Integer? (readonly)
88 89 90 |
# File 'lib/net/http/connection_pool/connection.rb', line 88 def proxy_port @proxy_port end |
#proxy_user ⇒ String? (readonly)
91 92 93 |
# File 'lib/net/http/connection_pool/connection.rb', line 91 def proxy_user @proxy_user end |
#read_timeout ⇒ Numeric?
97 98 99 |
# File 'lib/net/http/connection_pool/connection.rb', line 97 def read_timeout @read_timeout end |
#ssl ⇒ Boolean (readonly)
73 74 75 |
# File 'lib/net/http/connection_pool/connection.rb', line 73 def ssl @ssl end |
#ssl_ca_file ⇒ String? (readonly)
79 80 81 |
# File 'lib/net/http/connection_pool/connection.rb', line 79 def ssl_ca_file @ssl_ca_file end |
#ssl_ca_path ⇒ String? (readonly)
82 83 84 |
# File 'lib/net/http/connection_pool/connection.rb', line 82 def ssl_ca_path @ssl_ca_path end |
#ssl_verify_peer ⇒ Boolean (readonly)
76 77 78 |
# File 'lib/net/http/connection_pool/connection.rb', line 76 def ssl_verify_peer @ssl_verify_peer end |
Instance Method Details
#key ⇒ String
Returns a key that can be used to group connections that connection to the same host.
121 122 123 124 125 126 127 128 129 |
# File 'lib/net/http/connection_pool/connection.rb', line 121 def key @key ||= begin %w( host port ssl ssl_verify_peer ssl_ca_file ssl_ca_path proxy_address proxy_port proxy_user proxy_password ).map{|part| send(part).to_s }.join(":") end end |
#proxy? ⇒ Boolean
Returns true if this connection proxies requests.
111 112 113 |
# File 'lib/net/http/connection_pool/connection.rb', line 111 def proxy? !!proxy_address end |
#request(*args, &block) ⇒ Object
115 116 117 |
# File 'lib/net/http/connection_pool/connection.rb', line 115 def request *args, &block pool.request(self, *args, &block) end |
#ssl? ⇒ Boolean
Returns true if this connection requires SSL.
100 101 102 |
# File 'lib/net/http/connection_pool/connection.rb', line 100 def ssl? @ssl end |
#ssl_verify_peer? ⇒ Boolean
Returns true if ssl connections should verify the peer certificate.
106 107 108 |
# File 'lib/net/http/connection_pool/connection.rb', line 106 def ssl_verify_peer? @ssl_verify_peer end |