Class: Net::HTTP::ConnectionPool::Session
- Inherits:
-
Object
- Object
- Net::HTTP::ConnectionPool::Session
- Defined in:
- lib/net/http/connection_pool/session.rb
Overview
Used by Net::HTTP::ConnectionPool to wrap Net::HTTP::Session objects. Users should never need to interact with these session wrappers.
Instance Attribute Summary collapse
- #created_at ⇒ Time readonly
- #http_session ⇒ Net::HTTPSession readonly
- #key ⇒ String readonly
- #last_used_at ⇒ Time readonly
Class Method Summary collapse
-
.start(connection, options = {}) ⇒ Session
Starts a new HTTP session and returns it wrapped in a Session object.
Instance Method Summary collapse
-
#finish ⇒ nil
Attempts to cleanly close the HTTP session.
-
#initialize(http_session, key) ⇒ Session
constructor
A new instance of Session.
- #read_timeout=(timeout) ⇒ Object
-
#request(*args) {|response| ... } ⇒ nil
Makes a HTTP request.
Constructor Details
#initialize(http_session, key) ⇒ Session
Returns a new instance of Session.
27 28 29 30 31 32 |
# File 'lib/net/http/connection_pool/session.rb', line 27 def initialize http_session, key @http_session = http_session @key = key @created_at = Time.now @last_used_at = nil end |
Instance Attribute Details
#created_at ⇒ Time (readonly)
41 42 43 |
# File 'lib/net/http/connection_pool/session.rb', line 41 def created_at @created_at end |
#http_session ⇒ Net::HTTPSession (readonly)
35 36 37 |
# File 'lib/net/http/connection_pool/session.rb', line 35 def http_session @http_session end |
#key ⇒ String (readonly)
38 39 40 |
# File 'lib/net/http/connection_pool/session.rb', line 38 def key @key end |
#last_used_at ⇒ Time (readonly)
44 45 46 |
# File 'lib/net/http/connection_pool/session.rb', line 44 def last_used_at @last_used_at end |
Class Method Details
.start(connection, options = {}) ⇒ Session
Starts a new HTTP session and returns it wrapped in a Net::HTTP::ConnectionPool::Session object.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/net/http/connection_pool/session.rb', line 89 def start connection, = {} http_args = [] http_args << connection.host http_args << connection.port if connection.proxy? http_args << connection.proxy_address http_args << connection.proxy_port http_args << connection.proxy_user http_args << connection.proxy_password end http = Net::HTTP.new(*http_args) http.set_debug_output([:debug_logger]) if [:debug_logger] http.open_timeout = [:open_timeout] || 15 if connection.ssl? http.use_ssl = true if connection.ssl_verify_peer? http.verify_mode = OpenSSL::SSL::VERIFY_PEER http.ca_file = connection.ssl_ca_file if connection.ssl_ca_file http.ca_path = connection.ssl_ca_path if connection.ssl_ca_path else http.verify_mode = OpenSSL::SSL::VERIFY_NONE end else http.use_ssl = false end http.start Session.new(http, connection.key) end |
Instance Method Details
#finish ⇒ nil
Attempts to cleanly close the HTTP session.
71 72 73 74 75 76 77 |
# File 'lib/net/http/connection_pool/session.rb', line 71 def finish begin http_session.finish if http_session.started? rescue IOError end nil end |
#read_timeout=(timeout) ⇒ Object
48 49 50 |
# File 'lib/net/http/connection_pool/session.rb', line 48 def read_timeout= timeout http_session.read_timeout = timeout end |
#request(*args) {|response| ... } ⇒ nil
Makes a HTTP request. See Net::HTTPSession#request documentation from the Ruby standard library for information about argments.
connection.request(Net::HTTP::Get.new('/')) do |response|
# Parse the response (status, headers and body) here.
# You should be done with the response by the end of the block.
end
63 64 65 66 67 |
# File 'lib/net/http/connection_pool/session.rb', line 63 def request *args, &block http_session.request(*args, &block) @last_used_at = Time.now nil end |