Class: HTTPClient::SessionManager
- Inherits:
-
Object
- Object
- HTTPClient::SessionManager
- Defined in:
- lib/httpclient/session.rb
Overview
Manages sessions for a HTTPClient instance.
Instance Attribute Summary collapse
-
#agent_name ⇒ Object
Name of this client.
-
#chunk_size ⇒ Object
Chunk size for chunked request.
-
#connect_retry ⇒ Object
Maximum retry count.
-
#connect_timeout ⇒ Object
Returns the value of attribute connect_timeout.
-
#debug_dev ⇒ Object
Device for dumping log for debugging.
-
#from ⇒ Object
Owner of this client.
-
#keep_alive_timeout ⇒ Object
Returns the value of attribute keep_alive_timeout.
-
#protocol_retry_count ⇒ Object
Returns the value of attribute protocol_retry_count.
-
#protocol_version ⇒ Object
Requested protocol version.
-
#read_block_size ⇒ Object
Returns the value of attribute read_block_size.
-
#receive_timeout ⇒ Object
Returns the value of attribute receive_timeout.
-
#send_timeout ⇒ Object
Returns the value of attribute send_timeout.
-
#socket_local ⇒ Object
Local address to bind local side of the socket to.
-
#socket_sync ⇒ Object
Boolean value for Socket#sync.
-
#ssl_config ⇒ Object
Returns the value of attribute ssl_config.
-
#strict_response_size_check ⇒ Object
Raise BadResponseError if response size does not match with Content-Length header in response.
-
#tcp_keepalive ⇒ Object
Boolean value to send TCP keepalive packets; no timing settings exist at present.
-
#test_loopback_http_response ⇒ Object
readonly
Returns the value of attribute test_loopback_http_response.
-
#transparent_gzip_decompression ⇒ Object
Returns the value of attribute transparent_gzip_decompression.
Instance Method Summary collapse
-
#initialize(client) ⇒ SessionManager
constructor
A new instance of SessionManager.
-
#keep(sess) ⇒ Object
assert: sess.last_used must not be nil.
- #proxy=(proxy) ⇒ Object
- #query(req, via_proxy) ⇒ Object
- #reset(uri) ⇒ Object
- #reset_all ⇒ Object
Constructor Details
#initialize(client) ⇒ SessionManager
Returns a new instance of SessionManager.
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/httpclient/session.rb', line 132 def initialize(client) @client = client @proxy = client.proxy @agent_name = nil @from = nil @protocol_version = nil @debug_dev = client.debug_dev @socket_sync = true @tcp_keepalive = false @chunk_size = ::HTTP::Message::Body::DEFAULT_CHUNK_SIZE @connect_timeout = 60 @connect_retry = 1 @send_timeout = 120 @receive_timeout = 60 # For each read_block_size bytes @keep_alive_timeout = 15 # '15' is from Apache 2 default @read_block_size = 1024 * 16 # follows net/http change in 1.8.7 @protocol_retry_count = 5 @ssl_config = nil @test_loopback_http_response = [] @transparent_gzip_decompression = false @strict_response_size_check = false @socket_local = Site.new @sess_pool = {} @sess_pool_mutex = Mutex.new @sess_pool_last_checked = Time.now end |
Instance Attribute Details
#agent_name ⇒ Object
Name of this client. Used for ‘User-Agent’ header in HTTP request.
96 97 98 |
# File 'lib/httpclient/session.rb', line 96 def agent_name @agent_name end |
#chunk_size ⇒ Object
Chunk size for chunked request
103 104 105 |
# File 'lib/httpclient/session.rb', line 103 def chunk_size @chunk_size end |
#connect_retry ⇒ Object
Maximum retry count. 0 for infinite.
113 114 115 |
# File 'lib/httpclient/session.rb', line 113 def connect_retry @connect_retry end |
#connect_timeout ⇒ Object
Returns the value of attribute connect_timeout.
111 112 113 |
# File 'lib/httpclient/session.rb', line 111 def connect_timeout @connect_timeout end |
#debug_dev ⇒ Object
Device for dumping log for debugging
105 106 107 |
# File 'lib/httpclient/session.rb', line 105 def debug_dev @debug_dev end |
#from ⇒ Object
Owner of this client. Used for ‘From’ header in HTTP request.
98 99 100 |
# File 'lib/httpclient/session.rb', line 98 def from @from end |
#keep_alive_timeout ⇒ Object
Returns the value of attribute keep_alive_timeout.
116 117 118 |
# File 'lib/httpclient/session.rb', line 116 def keep_alive_timeout @keep_alive_timeout end |
#protocol_retry_count ⇒ Object
Returns the value of attribute protocol_retry_count.
118 119 120 |
# File 'lib/httpclient/session.rb', line 118 def protocol_retry_count @protocol_retry_count end |
#protocol_version ⇒ Object
Requested protocol version
101 102 103 |
# File 'lib/httpclient/session.rb', line 101 def protocol_version @protocol_version end |
#read_block_size ⇒ Object
Returns the value of attribute read_block_size.
117 118 119 |
# File 'lib/httpclient/session.rb', line 117 def read_block_size @read_block_size end |
#receive_timeout ⇒ Object
Returns the value of attribute receive_timeout.
115 116 117 |
# File 'lib/httpclient/session.rb', line 115 def receive_timeout @receive_timeout end |
#send_timeout ⇒ Object
Returns the value of attribute send_timeout.
114 115 116 |
# File 'lib/httpclient/session.rb', line 114 def send_timeout @send_timeout end |
#socket_local ⇒ Object
Local address to bind local side of the socket to
124 125 126 |
# File 'lib/httpclient/session.rb', line 124 def socket_local @socket_local end |
#socket_sync ⇒ Object
Boolean value for Socket#sync
107 108 109 |
# File 'lib/httpclient/session.rb', line 107 def socket_sync @socket_sync end |
#ssl_config ⇒ Object
Returns the value of attribute ssl_config.
126 127 128 |
# File 'lib/httpclient/session.rb', line 126 def ssl_config @ssl_config end |
#strict_response_size_check ⇒ Object
Raise BadResponseError if response size does not match with Content-Length header in response.
121 122 123 |
# File 'lib/httpclient/session.rb', line 121 def strict_response_size_check @strict_response_size_check end |
#tcp_keepalive ⇒ Object
Boolean value to send TCP keepalive packets; no timing settings exist at present
109 110 111 |
# File 'lib/httpclient/session.rb', line 109 def tcp_keepalive @tcp_keepalive end |
#test_loopback_http_response ⇒ Object (readonly)
Returns the value of attribute test_loopback_http_response.
128 129 130 |
# File 'lib/httpclient/session.rb', line 128 def test_loopback_http_response @test_loopback_http_response end |
#transparent_gzip_decompression ⇒ Object
Returns the value of attribute transparent_gzip_decompression.
130 131 132 |
# File 'lib/httpclient/session.rb', line 130 def transparent_gzip_decompression @transparent_gzip_decompression end |
Instance Method Details
#keep(sess) ⇒ Object
assert: sess.last_used must not be nil
195 196 197 |
# File 'lib/httpclient/session.rb', line 195 def keep(sess) add_cached_session(sess) end |
#proxy=(proxy) ⇒ Object
165 166 167 168 169 170 171 |
# File 'lib/httpclient/session.rb', line 165 def proxy=(proxy) if proxy.nil? @proxy = nil else @proxy = Site.new(proxy) end end |
#query(req, via_proxy) ⇒ Object
173 174 175 176 177 178 179 180 181 182 183 |
# File 'lib/httpclient/session.rb', line 173 def query(req, via_proxy) req.http_body.chunk_size = @chunk_size if req.http_body sess = get_session(req, via_proxy) begin sess.query(req) rescue sess.close raise end sess end |
#reset(uri) ⇒ Object
185 186 187 188 |
# File 'lib/httpclient/session.rb', line 185 def reset(uri) site = Site.new(uri) close(site) end |
#reset_all ⇒ Object
190 191 192 |
# File 'lib/httpclient/session.rb', line 190 def reset_all close_all end |