net-http-persistent 1.6.1 → 1.7

Sign up to get free protection for your applications and to get access to all the features.
data.tar.gz.sig CHANGED
Binary file
@@ -1,12 +1,21 @@
1
+ === 1.7 / 2011-04-17
2
+
3
+ * Minor Enhancement
4
+ * Added Net::HTTP::Persistent#pipeline which integrates with
5
+ net-http-pipeline when it is present.
6
+ * Bug Fix
7
+ * Perform a case-insensitive check of the URI scheme for HTTPS URIs
8
+
1
9
  === 1.6.1 / 2011-03-08
2
10
 
3
11
  * Bug Fix
4
12
  * Net::HTTP::Persistent#request now handles Errno::EINVAL as a connection
5
- reset and will be retried for idempotent requests.
13
+ reset and will be retried for idempotent requests. Reported by Aaron
14
+ Qian.
6
15
 
7
16
  === 1.6 / 2011-03-01
8
17
 
9
- * Minor Engancement
18
+ * Minor Enhancement
10
19
  * Added Net::HTTP::Persistent#socket_options to set multiple socket options
11
20
  at socket startup.
12
21
 
@@ -3,6 +3,11 @@ require 'net/http/faster'
3
3
  require 'uri'
4
4
  require 'cgi' # for escaping
5
5
 
6
+ begin
7
+ require 'net/http/pipeline'
8
+ rescue LoadError
9
+ end
10
+
6
11
  ##
7
12
  # Persistent connections for Net::HTTP
8
13
  #
@@ -37,7 +42,7 @@ class Net::HTTP::Persistent
37
42
  ##
38
43
  # The version of Net::HTTP::Persistent use are using
39
44
 
40
- VERSION = '1.6.1'
45
+ VERSION = '1.7'
41
46
 
42
47
  ##
43
48
  # Error class for errors raised by Net::HTTP::Persistent. Various
@@ -228,7 +233,7 @@ class Net::HTTP::Persistent
228
233
  unless connection = connections[connection_id] then
229
234
  connections[connection_id] = Net::HTTP.new(*net_http_args)
230
235
  connection = connections[connection_id]
231
- ssl connection if uri.scheme == 'https'
236
+ ssl connection if uri.scheme.downcase == 'https'
232
237
  end
233
238
 
234
239
  unless connection.started? then
@@ -239,7 +244,7 @@ class Net::HTTP::Persistent
239
244
  connection.start
240
245
 
241
246
  socket = connection.instance_variable_get :@socket
242
-
247
+
243
248
  if socket then # for fakeweb
244
249
  @socket_options.each do |option|
245
250
  socket.io.setsockopt(*option)
@@ -307,6 +312,23 @@ class Net::HTTP::Persistent
307
312
  (uri =~ /^https?:/) ? uri : "http://#{uri}"
308
313
  end
309
314
 
315
+ ##
316
+ # Pipelines +requests+ to the HTTP server at +uri+ yielding responses if a
317
+ # block is given. Returns all responses recieved.
318
+ #
319
+ # See
320
+ # Net::HTTP::Pipeline[http://docs.seattlerb.org/net-http-pipeline/Net/HTTP/Pipeline.html]
321
+ # for further details.
322
+ #
323
+ # Only if <tt>net-http-pipeline</tt> was required before
324
+ # <tt>net-http-persistent</tt> #pipeline will be present.
325
+
326
+ def pipeline uri, requests, &block # :yields: responses
327
+ connection = connection_for uri
328
+
329
+ connection.pipeline requests, &block
330
+ end
331
+
310
332
  ##
311
333
  # Creates a URI for an HTTP proxy server from ENV variables.
312
334
  #
@@ -417,7 +439,7 @@ class Net::HTTP::Persistent
417
439
 
418
440
  ##
419
441
  # Shuts down all connections for +thread+.
420
- #
442
+ #
421
443
  # Uses the current thread by default.
422
444
  #
423
445
  # If you've used Net::HTTP::Persistent across multiple threads you should
@@ -451,7 +473,7 @@ class Net::HTTP::Persistent
451
473
  # connections! Call #shutdown at the appropriate time instead!
452
474
  #
453
475
  # Use this method only as a last resort!
454
-
476
+
455
477
  def shutdown_in_all_threads
456
478
  Thread.list.each do |thread|
457
479
  shutdown thread
@@ -1,3 +1,4 @@
1
+ require 'rubygems'
1
2
  require 'minitest/autorun'
2
3
  require 'net/http/persistent'
3
4
  require 'openssl'
@@ -61,21 +62,24 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
61
62
  @finished += 1
62
63
  @socket = nil
63
64
  end
65
+ def finished?
66
+ @finished >= 1
67
+ end
68
+ def pipeline requests, &block
69
+ requests.map { |r| r.path }
70
+ end
71
+ def reset?
72
+ @started == @finished + 1
73
+ end
64
74
  def start
65
75
  @started += 1
66
76
  io = Object.new
67
77
  def io.setsockopt(*a) @setsockopts ||= []; @setsockopts << a end
68
78
  @socket = Net::BufferedIO.new io
69
79
  end
70
- def reset?
71
- @started == @finished + 1
72
- end
73
80
  def started?
74
81
  @started >= 1
75
82
  end
76
- def finished?
77
- @finished >= 1
78
- end
79
83
  end
80
84
 
81
85
  def basic_connection
@@ -285,6 +289,22 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
285
289
  assert_equal expected, socket.io.instance_variable_get(:@setsockopts)
286
290
  end
287
291
 
292
+ def test_connection_for_ssl
293
+ uri = URI.parse 'https://example.com/path'
294
+ c = @http.connection_for uri
295
+
296
+ assert c.started?
297
+ assert c.use_ssl?
298
+ end
299
+
300
+ def test_connection_for_ssl_case
301
+ uri = URI.parse 'HTTPS://example.com/path'
302
+ c = @http.connection_for uri
303
+
304
+ assert c.started?
305
+ assert c.use_ssl?
306
+ end
307
+
288
308
  def test_error_message
289
309
  c = basic_connection
290
310
  reqs[c.object_id] = 5
@@ -347,6 +367,25 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
347
367
  assert_equal 'https://example', @http.normalize_uri('https://example')
348
368
  end
349
369
 
370
+ def test_pipeline
371
+ skip 'net-http-pipeline not installed' unless defined?(Net::HTTP::Pipeline)
372
+
373
+ cached = basic_connection
374
+ cached.start
375
+ conns['example.com:80'] = cached
376
+
377
+ requests = [
378
+ Net::HTTP::Get.new((@uri + '1').request_uri),
379
+ Net::HTTP::Get.new((@uri + '2').request_uri),
380
+ ]
381
+
382
+ responses = @http.pipeline @uri, requests
383
+
384
+ assert_equal 2, responses.length
385
+ assert_equal '/1', responses.first
386
+ assert_equal '/2', responses.last
387
+ end
388
+
350
389
  def test_proxy_from_env
351
390
  ENV['HTTP_PROXY'] = 'proxy.example'
352
391
  ENV['HTTP_PROXY_USER'] = 'johndoe'
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: 13
4
+ hash: 1
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
- - 6
9
- - 1
10
- version: 1.6.1
8
+ - 7
9
+ version: "1.7"
11
10
  platform: ruby
12
11
  authors:
13
12
  - Eric Hodel
@@ -36,8 +35,7 @@ cert_chain:
36
35
  x52qPcexcYZR7w==
37
36
  -----END CERTIFICATE-----
38
37
 
39
- date: 2011-03-08 00:00:00 -08:00
40
- default_executable:
38
+ date: 2011-04-17 00:00:00 Z
41
39
  dependencies:
42
40
  - !ruby/object:Gem::Dependency
43
41
  name: minitest
@@ -63,12 +61,12 @@ dependencies:
63
61
  requirements:
64
62
  - - ">="
65
63
  - !ruby/object:Gem::Version
66
- hash: 41
64
+ hash: 35
67
65
  segments:
68
66
  - 2
69
67
  - 9
70
- - 1
71
- version: 2.9.1
68
+ - 4
69
+ version: 2.9.4
72
70
  type: :development
73
71
  version_requirements: *id002
74
72
  description: |-
@@ -102,7 +100,6 @@ files:
102
100
  - lib/net/http/faster.rb
103
101
  - lib/net/http/persistent.rb
104
102
  - test/test_net_http_persistent.rb
105
- has_rdoc: true
106
103
  homepage: http://seattlerb.rubyforge.org/net-http-persistent
107
104
  licenses: []
108
105
 
@@ -133,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
133
130
  requirements: []
134
131
 
135
132
  rubyforge_project: net-http-persistent
136
- rubygems_version: 1.6.1
133
+ rubygems_version: 1.7.2
137
134
  signing_key:
138
135
  specification_version: 3
139
136
  summary: Manages persistent connections using Net::HTTP plus a speed fix for 1.8
metadata.gz.sig CHANGED
Binary file