Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added JRuby compatibility by default for HTTPS

I am told that JRuby lacks OpenSSL::SSL::Session, so this patch disables
SSL session reuse if the constant cannot be found.  For JRuby users this
will cost extra for SSL negotiation per connect (~50ms IIRC, depending
upon the server).
  • Loading branch information...
commit 0feb9b1f4578556f9c9e105ae73bdc3716e02c4f 1 parent 881c433
@drbrain authored
View
8 History.txt
@@ -1,4 +1,10 @@
-=== 2.6 / 2010-03-26
+=== 2.7 / 2012-06-06
+
+* Minor enhancement
+ * Added JRuby compatibility by default for HTTPS connections. (JRuby lacks
+ OpenSSL::SSL::Session.)
+
+=== 2.6 / 2012-03-26
* Minor enhancement
* Net::HTTP::Persistent#idle_timeout may be set to nil to disable expiration
View
4 lib/net/http/persistent.rb
@@ -176,7 +176,7 @@ class Net::HTTP::Persistent
##
# The version of Net::HTTP::Persistent you are using
- VERSION = '2.6'
+ VERSION = '2.7'
##
# Error class for errors raised by Net::HTTP::Persistent. Various
@@ -404,7 +404,7 @@ def initialize name = nil, proxy = nil
@generation = 0 # incremented when proxy URI changes
@ssl_generation = 0 # incremented when SSL session variables change
- @reuse_ssl_sessions = true
+ @reuse_ssl_sessions = OpenSSL::SSL.const_defined? :Session
@retry_change_requests = false
View
19 test/test_net_http_persistent.rb
@@ -141,6 +141,10 @@ def touts
def test_initialize
assert_nil @http.proxy_uri
+
+ ssl_session_exists = OpenSSL::SSL.const_defined? :Session
+
+ assert_equal ssl_session_exists, @http.reuse_ssl_sessions
end
def test_initialize_name
@@ -148,6 +152,21 @@ def test_initialize_name
assert_equal 'name', http.name
end
+ def test_initialize_no_ssl_session
+ skip "OpenSSL::SSL::Session does not exist on #{RUBY_PLATFORM}" unless
+ OpenSSL::SSL.const_defined? :Session
+
+ ssl_session = OpenSSL::SSL::Session
+
+ OpenSSL::SSL.send :remove_const, :Session
+
+ http = Net::HTTP::Persistent.new
+
+ refute http.reuse_ssl_sessions
+ ensure
+ OpenSSL::SSL.const_set :Session, ssl_session if ssl_session
+ end
+
def test_initialize_proxy
proxy_uri = URI.parse 'http://proxy.example'
Please sign in to comment.
Something went wrong with that request. Please try again.