net-http-persistent 2.3.1 → 2.3.2

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,3 +1,8 @@
1
+ === 2.3.2
2
+
3
+ * Bug fix
4
+ * Finish connections that were closed by Net::HTTP so they can be restarted.
5
+
1
6
  === 2.3.1 / 2011-10-26
2
7
 
3
8
  * Bug fix
@@ -2,7 +2,7 @@
2
2
  .gemtest
3
3
  History.txt
4
4
  Manifest.txt
5
- README.txt
5
+ README.rdoc
6
6
  Rakefile
7
7
  lib/net/http/faster.rb
8
8
  lib/net/http/persistent.rb
@@ -23,6 +23,31 @@ and retry according to RFC 2616.
23
23
  * Pure ruby
24
24
  * Timeout-less speed boost for Ruby 1.8 (by Aaron Patterson)
25
25
 
26
+ == SYNOPSIS
27
+
28
+ The following example will make two requests to the same server. The
29
+ connection is kept alive between requests:
30
+
31
+ require 'net/http/persistent'
32
+
33
+ uri = URI 'http://example.com/awesome/web/service'
34
+
35
+ http = Net::HTTP::Persistent.new 'my_app_name'
36
+
37
+ # perform a GET
38
+ response = http.request uri
39
+
40
+ # create a POST
41
+ post_uri = uri + 'create'
42
+ post = Net::HTTP::Post.new post_uri.path
43
+ post.set_form_data 'some' => 'cool data'
44
+
45
+ # perform the POST, the URI is always required
46
+ response http.request post_uri, post
47
+
48
+ Please see the documentation for +Net::HTTP::Persistent+ for more information,
49
+ including how to handle SSL connections.
50
+
26
51
  == INSTALL:
27
52
 
28
53
  gem install net-http-persistent
data/Rakefile CHANGED
@@ -9,6 +9,9 @@ Hoe.plugin :minitest
9
9
  Hoe.spec 'net-http-persistent' do |p|
10
10
  developer 'Eric Hodel', 'drbrain@segment7.net'
11
11
 
12
+ self.readme_file = 'README.rdoc'
13
+ self.extra_rdoc_files += Dir['*.rdoc']
14
+
12
15
  rdoc_locations <<
13
16
  'docs.seattlerb.org:/data/www/docs.seattlerb.org/net-http-persistent/'
14
17
  end
@@ -149,7 +149,7 @@ class Net::HTTP::Persistent
149
149
  ##
150
150
  # The version of Net::HTTP::Persistent you are using
151
151
 
152
- VERSION = '2.3.1'
152
+ VERSION = '2.3.2'
153
153
 
154
154
  ##
155
155
  # Error class for errors raised by Net::HTTP::Persistent. Various
@@ -386,7 +386,7 @@ class Net::HTTP::Persistent
386
386
  net_http_args.concat @proxy_args
387
387
  end
388
388
 
389
- connection = connections[connection_id]
389
+ connection = connections[connection_id]
390
390
 
391
391
  unless connection = connections[connection_id] then
392
392
  connections[connection_id] = http_class.new(*net_http_args)
@@ -480,6 +480,38 @@ class Net::HTTP::Persistent
480
480
  retry_change_requests or idempotent?(req)
481
481
  end
482
482
 
483
+ if RUBY_VERSION > '1.9' then
484
+ ##
485
+ # Workaround for missing Net::HTTPHeader#connection_close? on Ruby 1.8
486
+
487
+ def connection_close? header
488
+ header.connection_close?
489
+ end
490
+
491
+ ##
492
+ # Workaround for missing Net::HTTPHeader#connection_keep_alive? on Ruby 1.8
493
+
494
+ def connection_keep_alive? header
495
+ header.connection_keep_alive?
496
+ end
497
+ else
498
+ ##
499
+ # Workaround for missing Net::HTTPRequest#connection_close? on Ruby 1.8
500
+
501
+ def connection_close? header
502
+ header['connection'] =~ /close/ or header['proxy-connection'] =~ /close/
503
+ end
504
+
505
+ ##
506
+ # Workaround for missing Net::HTTPRequest#connection_keep_alive? on Ruby
507
+ # 1.8
508
+
509
+ def connection_keep_alive? header
510
+ header['connection'] =~ /keep-alive/ or
511
+ header['proxy-connection'] =~ /keep-alive/
512
+ end
513
+ end
514
+
483
515
  ##
484
516
  # If a connection hasn't been used since max_age it will be reset and reused
485
517
 
@@ -587,6 +619,13 @@ class Net::HTTP::Persistent
587
619
  begin
588
620
  Thread.current[@request_key][connection_id] += 1
589
621
  response = connection.request req, &block
622
+
623
+ if connection_close?(req) or
624
+ (response.http_version <= '1.0' and
625
+ not connection_keep_alive?(response)) or
626
+ connection_close?(response) then
627
+ connection.finish
628
+ end
590
629
  rescue Net::HTTPBadResponse => e
591
630
  message = error_message connection
592
631
 
@@ -99,10 +99,12 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
99
99
 
100
100
  def connection
101
101
  c = basic_connection
102
+ touts[c.object_id] = Time.now
102
103
 
103
104
  def c.request(req)
104
105
  @req = req
105
106
  r = Net::HTTPResponse.allocate
107
+ r.instance_variable_set :@header, {}
106
108
  def r.http_version() '1.1' end
107
109
  def r.read_body() :read_body end
108
110
  yield r if block_given?
@@ -575,7 +577,10 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
575
577
  c = basic_connection
576
578
  def c.request(*a)
577
579
  if defined? @called then
578
- Net::HTTPResponse.allocate
580
+ r = Net::HTTPResponse.allocate
581
+ r.instance_variable_set :@header, {}
582
+ def r.http_version() '1.1' end
583
+ r
579
584
  else
580
585
  @called = true
581
586
  raise Net::HTTPBadResponse
@@ -629,7 +634,35 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
629
634
  assert_equal 1, reqs[c.object_id]
630
635
  end
631
636
 
632
- def test_request_connection
637
+ def test_request_close_1_0
638
+ c = connection
639
+
640
+ def c.request req
641
+ @req = req
642
+ r = Net::HTTPResponse.allocate
643
+ r.instance_variable_set :@header, {}
644
+ def r.http_version() '1.0' end
645
+ def r.read_body() :read_body end
646
+ yield r if block_given?
647
+ r
648
+ end
649
+
650
+ request = Net::HTTP::Get.new @uri.request_uri
651
+
652
+ res = @http.request @uri, request
653
+ req = c.req
654
+
655
+ assert_kind_of Net::HTTPResponse, res
656
+
657
+ assert_kind_of Net::HTTP::Get, req
658
+ assert_equal '/path', req.path
659
+ assert_equal 'keep-alive', req['connection']
660
+ assert_equal '30', req['keep-alive']
661
+
662
+ assert c.finished?
663
+ end
664
+
665
+ def test_request_connection_close_request
633
666
  c = connection
634
667
 
635
668
  request = Net::HTTP::Get.new @uri.request_uri
@@ -644,6 +677,37 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
644
677
  assert_equal '/path', req.path
645
678
  assert_equal 'close', req['connection']
646
679
  assert_equal nil, req['keep-alive']
680
+
681
+ assert c.finished?
682
+ end
683
+
684
+ def test_request_connection_close_response
685
+ c = connection
686
+
687
+ def c.request req
688
+ @req = req
689
+ r = Net::HTTPResponse.allocate
690
+ r.instance_variable_set :@header, {}
691
+ r['connection'] = 'close'
692
+ def r.http_version() '1.1' end
693
+ def r.read_body() :read_body end
694
+ yield r if block_given?
695
+ r
696
+ end
697
+
698
+ request = Net::HTTP::Get.new @uri.request_uri
699
+
700
+ res = @http.request @uri, request
701
+ req = c.req
702
+
703
+ assert_kind_of Net::HTTPResponse, res
704
+
705
+ assert_kind_of Net::HTTP::Get, req
706
+ assert_equal '/path', req.path
707
+ assert_equal 'keep-alive', req['connection']
708
+ assert_equal '30', req['keep-alive']
709
+
710
+ assert c.finished?
647
711
  end
648
712
 
649
713
  def test_request_invalid
@@ -664,7 +728,10 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
664
728
 
665
729
  def c.request(*a)
666
730
  if defined? @called then
667
- Net::HTTPResponse.allocate
731
+ r = Net::HTTPResponse.allocate
732
+ r.instance_variable_set :@header, {}
733
+ def r.http_version() '1.1' end
734
+ r
668
735
  else
669
736
  @called = true
670
737
  raise Errno::EINVAL, "write"
@@ -694,7 +761,10 @@ class TestNetHttpPersistent < MiniTest::Unit::TestCase
694
761
  touts[c.object_id] = Time.now
695
762
  def c.request(*a)
696
763
  if defined? @called then
697
- Net::HTTPResponse.allocate
764
+ r = Net::HTTPResponse.allocate
765
+ r.instance_variable_set :@header, {}
766
+ def r.http_version() '1.1' end
767
+ r
698
768
  else
699
769
  @called = true
700
770
  raise Errno::ECONNRESET
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: net-http-persistent
3
3
  version: !ruby/object:Gem::Version
4
- hash: 1
4
+ hash: 7
5
5
  prerelease:
6
6
  segments:
7
7
  - 2
8
8
  - 3
9
- - 1
10
- version: 2.3.1
9
+ - 2
10
+ version: 2.3.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Eric Hodel
@@ -36,7 +36,7 @@ cert_chain:
36
36
  x52qPcexcYZR7w==
37
37
  -----END CERTIFICATE-----
38
38
 
39
- date: 2011-10-27 00:00:00 Z
39
+ date: 2011-11-09 00:00:00 Z
40
40
  dependencies:
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: minitest
@@ -88,13 +88,13 @@ extensions: []
88
88
  extra_rdoc_files:
89
89
  - History.txt
90
90
  - Manifest.txt
91
- - README.txt
91
+ - README.rdoc
92
92
  files:
93
93
  - .autotest
94
94
  - .gemtest
95
95
  - History.txt
96
96
  - Manifest.txt
97
- - README.txt
97
+ - README.rdoc
98
98
  - Rakefile
99
99
  - lib/net/http/faster.rb
100
100
  - lib/net/http/persistent.rb
@@ -107,7 +107,7 @@ licenses: []
107
107
  post_install_message:
108
108
  rdoc_options:
109
109
  - --main
110
- - README.txt
110
+ - README.rdoc
111
111
  require_paths:
112
112
  - lib
113
113
  required_ruby_version: !ruby/object:Gem::Requirement
metadata.gz.sig CHANGED
Binary file