net-http-persistent 1.5.2 → 1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data.tar.gz.sig CHANGED
Binary file
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ === 1.6 / 2011-03-01
2
+
3
+ * Minor Engancement
4
+ * Added Net::HTTP::Persistent#socket_options to set multiple socket options
5
+ at socket startup.
6
+
1
7
  === 1.5.2 / 2011-02-24
2
8
 
3
9
  * Bug Fix
@@ -37,7 +37,7 @@ class Net::HTTP::Persistent
37
37
  ##
38
38
  # The version of Net::HTTP::Persistent use are using
39
39
 
40
- VERSION = '1.5.2'
40
+ VERSION = '1.6'
41
41
 
42
42
  ##
43
43
  # Error class for errors raised by Net::HTTP::Persistent. Various
@@ -123,6 +123,17 @@ class Net::HTTP::Persistent
123
123
 
124
124
  attr_reader :request_key # :nodoc:
125
125
 
126
+ ##
127
+ # An array of options for Socket#setsockopt.
128
+ #
129
+ # By default the TCP_NODELAY option is set on sockets.
130
+ #
131
+ # To set additional options append them to this array:
132
+ #
133
+ # http.socket_options << [Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1]
134
+
135
+ attr_reader :socket_options
136
+
126
137
  ##
127
138
  # SSL verification callback. Used when ca_file is set.
128
139
 
@@ -174,12 +185,16 @@ class Net::HTTP::Persistent
174
185
  @proxy_connection_id = [nil, *@proxy_args].join ':'
175
186
  end
176
187
 
177
- @debug_output = nil
178
- @headers = {}
179
- @http_versions = {}
180
- @keep_alive = 30
181
- @open_timeout = nil
182
- @read_timeout = nil
188
+ @debug_output = nil
189
+ @headers = {}
190
+ @http_versions = {}
191
+ @keep_alive = 30
192
+ @open_timeout = nil
193
+ @read_timeout = nil
194
+ @socket_options = []
195
+
196
+ @socket_options << [Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1] if
197
+ Socket.const_defined? :TCP_NODELAY
183
198
 
184
199
  key = ['net_http_persistent', name, 'connections'].compact.join '_'
185
200
  @connection_key = key.intern
@@ -223,10 +238,12 @@ class Net::HTTP::Persistent
223
238
 
224
239
  connection.start
225
240
 
226
- if Socket.const_defined? :TCP_NODELAY then
227
- socket = connection.instance_variable_get :@socket
228
- socket.io.setsockopt Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1 if
229
- socket # for fakeweb
241
+ socket = connection.instance_variable_get :@socket
242
+
243
+ if socket then # for fakeweb
244
+ @socket_options.each do |option|
245
+ socket.io.setsockopt(*option)
246
+ end
230
247
  end
231
248
  end
232
249
 
@@ -9,7 +9,7 @@ class Net::HTTP
9
9
  def connect
10
10
  unless use_ssl? then
11
11
  io = Object.new
12
- def io.setsockopt(*a) @setsockopt = a end
12
+ def io.setsockopt(*a) @setsockopts ||= []; @setsockopts << a end
13
13
 
14
14
  @socket = Net::BufferedIO.new io
15
15
 
@@ -17,7 +17,7 @@ class Net::HTTP
17
17
  end
18
18
 
19
19
  io = open '/dev/null'
20
- def io.setsockopt(*a) @setsockopt = a end
20
+ def io.setsockopt(*a) @setsockopts ||= []; @setsockopts << a end
21
21
 
22
22
  @ssl_context ||= OpenSSL::SSL::SSLContext.new
23
23
 
@@ -64,7 +64,7 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
64
64
  def start
65
65
  @started += 1
66
66
  io = Object.new
67
- def io.setsockopt(*a) @setsockopt = a end
67
+ def io.setsockopt(*a) @setsockopts ||= []; @setsockopts << a end
68
68
  @socket = Net::BufferedIO.new io
69
69
  end
70
70
  def reset?
@@ -147,12 +147,12 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
147
147
 
148
148
  socket = c.instance_variable_get :@socket
149
149
  expected = if Socket.const_defined? :TCP_NODELAY then
150
- [Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1]
150
+ [[Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1]]
151
151
  else
152
- nil
152
+ []
153
153
  end
154
154
 
155
- assert_equal expected, socket.io.instance_variable_get(:@setsockopt)
155
+ assert_equal expected, socket.io.instance_variable_get(:@setsockopts)
156
156
  end
157
157
 
158
158
  def test_connection_for_cached
@@ -271,6 +271,20 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
271
271
  assert_match %r%connection refused%, e.message
272
272
  end
273
273
 
274
+ def test_connection_for_socket_options
275
+ @http.socket_options << [Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1]
276
+ c = @http.connection_for @uri
277
+
278
+ socket = c.instance_variable_get :@socket
279
+
280
+ expected = []
281
+ expected << [Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1] if
282
+ Socket.const_defined? :TCP_NODELAY
283
+ expected << [Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1]
284
+
285
+ assert_equal expected, socket.io.instance_variable_get(:@setsockopts)
286
+ end
287
+
274
288
  def test_error_message
275
289
  c = basic_connection
276
290
  reqs[c.object_id] = 5
metadata CHANGED
@@ -1,13 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-http-persistent
3
3
  version: !ruby/object:Gem::Version
4
- hash: 7
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 5
9
- - 2
10
- version: 1.5.2
8
+ - 6
9
+ version: "1.6"
11
10
  platform: ruby
12
11
  authors:
13
12
  - Eric Hodel
@@ -36,7 +35,7 @@ cert_chain:
36
35
  x52qPcexcYZR7w==
37
36
  -----END CERTIFICATE-----
38
37
 
39
- date: 2011-02-24 00:00:00 -08:00
38
+ date: 2011-03-01 00:00:00 -08:00
40
39
  default_executable:
41
40
  dependencies:
42
41
  - !ruby/object:Gem::Dependency
@@ -141,7 +140,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
140
  requirements: []
142
141
 
143
142
  rubyforge_project: seattlerb
144
- rubygems_version: 1.5.2
143
+ rubygems_version: 1.6.0
145
144
  signing_key:
146
145
  specification_version: 3
147
146
  summary: Persistent connections using Net::HTTP plus a speed fix for 1.8
metadata.gz.sig CHANGED
Binary file