softwaregravy-net-http-persistent 2.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.
@@ -0,0 +1,101 @@
1
+ require 'rubygems'
2
+ require 'minitest/autorun'
3
+ require 'net/http/persistent'
4
+ require 'openssl'
5
+ require 'webrick'
6
+ require 'webrick/ssl'
7
+
8
+ ##
9
+ # This test is based on (and contains verbatim code from) the Net::HTTP tests
10
+ # in ruby
11
+
12
+ class TestNetHttpPersistentSSLReuse < MiniTest::Unit::TestCase
13
+
14
+ class NullWriter
15
+ def <<(s) end
16
+ def puts(*args) end
17
+ def print(*args) end
18
+ def printf(*args) end
19
+ end
20
+
21
+ def setup
22
+ @name = OpenSSL::X509::Name.parse 'CN=localhost'
23
+
24
+ @key = OpenSSL::PKey::RSA.new 512
25
+
26
+ @cert = OpenSSL::X509::Certificate.new
27
+ @cert.version = 2
28
+ @cert.serial = 0
29
+ @cert.not_before = Time.now
30
+ @cert.not_after = Time.now + 300
31
+ @cert.public_key = @key.public_key
32
+ @cert.subject = @name
33
+
34
+ @host = 'localhost'
35
+ @port = 10082
36
+
37
+ config = {
38
+ :BindAddress => @host,
39
+ :Port => @port,
40
+ :Logger => WEBrick::Log.new(NullWriter.new),
41
+ :AccessLog => [],
42
+ :ShutDownSocketWithoutClose => true,
43
+ :ServerType => Thread,
44
+ :SSLEnable => true,
45
+ :SSLCertificate => @cert,
46
+ :SSLPrivateKey => @key,
47
+ :SSLStartImmediately => true,
48
+ }
49
+
50
+ @server = WEBrick::HTTPServer.new config
51
+
52
+ @server.mount_proc '/' do |req, res|
53
+ res.body = "ok"
54
+ end
55
+
56
+ @server.start
57
+
58
+ begin
59
+ TCPSocket.open(@host, @port).close
60
+ rescue Errno::ECONNREFUSED
61
+ sleep 0.2
62
+ n_try_max -= 1
63
+ raise 'cannot spawn server; give up' if n_try_max < 0
64
+ retry
65
+ end
66
+ end
67
+
68
+ def teardown
69
+ if @server then
70
+ @server.shutdown
71
+ sleep 0.01 until @server.status == :Stop
72
+ end
73
+ end
74
+
75
+ def test_ssl_connection_reuse
76
+ @http = Net::HTTP::Persistent::SSLReuse.new @host, @port
77
+ @http.use_ssl = true
78
+ @http.verify_mode = OpenSSL::SSL::VERIFY_PEER
79
+ @http.verify_callback = proc do |_, store_ctx|
80
+ store_ctx.current_cert.to_der == @cert.to_der
81
+ end
82
+
83
+ @http.start
84
+ @http.get '/'
85
+ @http.finish
86
+
87
+ @http.start
88
+ @http.get '/'
89
+ @http.finish
90
+
91
+ @http.start
92
+ @http.get '/'
93
+
94
+ socket = @http.instance_variable_get :@socket
95
+ ssl_socket = socket.io
96
+
97
+ assert ssl_socket.session_reused?
98
+ end
99
+
100
+ end
101
+
metadata ADDED
@@ -0,0 +1,103 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: softwaregravy-net-http-persistent
3
+ version: !ruby/object:Gem::Version
4
+ version: '2.6'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Eric Hodel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-05-09 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rdoc
16
+ requirement: &2156478500 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.10'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *2156478500
25
+ - !ruby/object:Gem::Dependency
26
+ name: hoe
27
+ requirement: &2156477720 !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ~>
31
+ - !ruby/object:Gem::Version
32
+ version: '3.0'
33
+ type: :development
34
+ prerelease: false
35
+ version_requirements: *2156477720
36
+ description: ! 'Manages persistent connections using Net::HTTP plus a speed fix for
37
+ Ruby 1.8.
38
+
39
+ It''s thread-safe too!
40
+
41
+
42
+ Using persistent HTTP connections can dramatically increase the speed of HTTP.
43
+
44
+ Creating a new HTTP connection for every request involves an extra TCP
45
+
46
+ round-trip and causes TCP congestion avoidance negotiation to start over.
47
+
48
+
49
+ Net::HTTP supports persistent connections with some API methods but does not
50
+
51
+ handle reconnection gracefully. Net::HTTP::Persistent supports reconnection
52
+
53
+ and retry according to RFC 2616.'
54
+ email:
55
+ - drbrain@segment7.net
56
+ executables: []
57
+ extensions: []
58
+ extra_rdoc_files:
59
+ - History.txt
60
+ - Manifest.txt
61
+ - README.rdoc
62
+ files:
63
+ - .autotest
64
+ - .gemtest
65
+ - History.txt
66
+ - Manifest.txt
67
+ - README.rdoc
68
+ - Rakefile
69
+ - lib/net/http/faster.rb
70
+ - lib/net/http/persistent.rb
71
+ - lib/net/http/persistent/ssl_reuse.rb
72
+ - test/test_net_http_persistent.rb
73
+ - test/test_net_http_persistent_ssl_reuse.rb
74
+ homepage: http://docs.seattlerb.org/net-http-persistent
75
+ licenses: []
76
+ post_install_message:
77
+ rdoc_options:
78
+ - --main
79
+ - README.rdoc
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ none: false
84
+ requirements:
85
+ - - ! '>='
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ required_rubygems_version: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ requirements: []
95
+ rubyforge_project: softwaregravy-net-http-persistent
96
+ rubygems_version: 1.8.10
97
+ signing_key:
98
+ specification_version: 3
99
+ summary: Manages persistent connections using Net::HTTP plus a speed fix for Ruby
100
+ 1.8
101
+ test_files:
102
+ - test/test_net_http_persistent.rb
103
+ - test/test_net_http_persistent_ssl_reuse.rb