Class: HTTPClient::SessionManager

Inherits:
Object
  • Object
show all
Defined in:
lib/httpclient/session.rb

Overview

Manages sessions for a HTTPClient instance.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ SessionManager

Returns a new instance of SessionManager.


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/httpclient/session.rb', line 109

def initialize(client)
  @client = client
  @proxy = client.proxy

  @agent_name = nil
  @from = nil

  @protocol_version = nil
  @debug_dev = client.debug_dev
  @socket_sync = true
  @chunk_size = 4096

  @connect_timeout = 60
  @connect_retry = 1
  @send_timeout = 120
  @receive_timeout = 60       # For each read_block_size bytes
  @read_block_size = 1024 * 16 # follows net/http change in 1.8.7
  @protocol_retry_count = 5

  @ssl_config = nil
  @test_loopback_http_response = []

  @sess_pool = []
  @sess_pool_mutex = Mutex.new
end

Instance Attribute Details

#agent_nameObject

Name of this client. Used for 'User-Agent' header in HTTP request.


84
85
86
# File 'lib/httpclient/session.rb', line 84

def agent_name
  @agent_name
end

#chunk_sizeObject

Chunk size for chunked request


91
92
93
# File 'lib/httpclient/session.rb', line 91

def chunk_size
  @chunk_size
end

#connect_retryObject

Maximum retry count. 0 for infinite.


99
100
101
# File 'lib/httpclient/session.rb', line 99

def connect_retry
  @connect_retry
end

#connect_timeoutObject

Returns the value of attribute connect_timeout


97
98
99
# File 'lib/httpclient/session.rb', line 97

def connect_timeout
  @connect_timeout
end

#debug_devObject

Device for dumping log for debugging


93
94
95
# File 'lib/httpclient/session.rb', line 93

def debug_dev
  @debug_dev
end

#fromObject

Owner of this client. Used for 'From' header in HTTP request.


86
87
88
# File 'lib/httpclient/session.rb', line 86

def from
  @from
end

#protocol_retry_countObject

Returns the value of attribute protocol_retry_count


103
104
105
# File 'lib/httpclient/session.rb', line 103

def protocol_retry_count
  @protocol_retry_count
end

#protocol_versionObject

Requested protocol version


89
90
91
# File 'lib/httpclient/session.rb', line 89

def protocol_version
  @protocol_version
end

#read_block_sizeObject

Returns the value of attribute read_block_size


102
103
104
# File 'lib/httpclient/session.rb', line 102

def read_block_size
  @read_block_size
end

#receive_timeoutObject

Returns the value of attribute receive_timeout


101
102
103
# File 'lib/httpclient/session.rb', line 101

def receive_timeout
  @receive_timeout
end

#send_timeoutObject

Returns the value of attribute send_timeout


100
101
102
# File 'lib/httpclient/session.rb', line 100

def send_timeout
  @send_timeout
end

#socket_syncObject

Boolean value for Socket#sync


95
96
97
# File 'lib/httpclient/session.rb', line 95

def socket_sync
  @socket_sync
end

#ssl_configObject

Returns the value of attribute ssl_config


105
106
107
# File 'lib/httpclient/session.rb', line 105

def ssl_config
  @ssl_config
end

#test_loopback_http_responseObject (readonly)

Returns the value of attribute test_loopback_http_response


107
108
109
# File 'lib/httpclient/session.rb', line 107

def test_loopback_http_response
  @test_loopback_http_response
end

Instance Method Details

#keep(sess) ⇒ Object


164
165
166
# File 'lib/httpclient/session.rb', line 164

def keep(sess)
  add_cached_session(sess)
end

#proxy=(proxy) ⇒ Object


135
136
137
138
139
140
141
# File 'lib/httpclient/session.rb', line 135

def proxy=(proxy)
  if proxy.nil?
    @proxy = nil
  else
    @proxy = Site.new(proxy)
  end
end

#query(req, via_proxy) ⇒ Object


143
144
145
146
147
148
149
150
151
152
153
# File 'lib/httpclient/session.rb', line 143

def query(req, via_proxy)
  req.body.chunk_size = @chunk_size
  sess = open(req.header.request_uri, via_proxy)
  begin
    sess.query(req)
  rescue
    sess.close
    raise
  end
  sess
end

#reset(uri) ⇒ Object


155
156
157
158
# File 'lib/httpclient/session.rb', line 155

def reset(uri)
  site = Site.new(uri)
  close(site)
end

#reset_allObject


160
161
162
# File 'lib/httpclient/session.rb', line 160

def reset_all
  close_all
end