[前][次][番号順一覧][スレッド一覧]

ruby-changes:71780

From: Karol <ko1@a...>
Date: Wed, 20 Apr 2022 13:01:27 +0900 (JST)
Subject: [ruby-changes:71780] cf73cf5981 (master): [ruby/net-http] Feature detect to make net/http usable with JRuby

https://git.ruby-lang.org/ruby.git/commit/?id=cf73cf5981

From cf73cf5981802f2bcc30aba07914acf4286cda5a Mon Sep 17 00:00:00 2001
From: Karol Bucek <kares@u...>
Date: Wed, 20 Apr 2022 06:01:02 +0200
Subject: [ruby/net-http] Feature detect to make net/http usable with JRuby

Handle missing session_new_cb= and do not call
session_cache_mode=, as JRuby SSL does not support
these methods.

https://github.com/ruby/net-http/commit/3237ef4d8c
---
 lib/net/http.rb             | 12 ++++++++----
 test/net/http/test_https.rb |  8 +++++---
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/lib/net/http.rb b/lib/net/http.rb
index dc8ed051f0..dd64a2d11e 100644
--- a/lib/net/http.rb
+++ b/lib/net/http.rb
@@ -1051,10 +1051,14 @@ module Net   #:nodoc: https://github.com/ruby/ruby/blob/trunk/lib/net/http.rb#L1051
           end
         end
         @ssl_context.set_params(ssl_parameters)
-        @ssl_context.session_cache_mode =
-          OpenSSL::SSL::SSLContext::SESSION_CACHE_CLIENT |
-          OpenSSL::SSL::SSLContext::SESSION_CACHE_NO_INTERNAL_STORE
-        @ssl_context.session_new_cb = proc {|sock, sess| @ssl_session = sess }
+        unless @ssl_context.session_cache_mode.nil? # a dummy method on JRuby
+          @ssl_context.session_cache_mode =
+              OpenSSL::SSL::SSLContext::SESSION_CACHE_CLIENT |
+                  OpenSSL::SSL::SSLContext::SESSION_CACHE_NO_INTERNAL_STORE
+        end
+        if @ssl_context.respond_to?(:session_new_cb) # not implemented under JRuby
+          @ssl_context.session_new_cb = proc {|sock, sess| @ssl_session = sess }
+        end
 
         # Still do the post_connection_check below even if connecting
         # to IP address
diff --git a/test/net/http/test_https.rb b/test/net/http/test_https.rb
index f4f1959a0e..72a69af1a5 100644
--- a/test/net/http/test_https.rb
+++ b/test/net/http/test_https.rb
@@ -152,12 +152,14 @@ class TestNetHTTPS < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/http/test_https.rb#L152
     end
 
     http.start
-    assert_equal false, http.instance_variable_get(:@socket).io.session_reused?
+    session_reused = http.instance_variable_get(:@socket).io.session_reused?
+    assert_false session_reused unless session_reused.nil? # can not detect re-use under JRuby
     http.get("/")
     http.finish
 
     http.start
-    assert_equal true, http.instance_variable_get(:@socket).io.session_reused?
+    session_reused = http.instance_variable_get(:@socket).io.session_reused?
+    assert_true session_reused unless session_reused.nil? # can not detect re-use under JRuby
     assert_equal $test_net_http_data, http.get("/").body
     http.finish
   end
@@ -301,7 +303,7 @@ class TestNetHTTPS < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/net/http/test_https.rb#L303
     ex = assert_raise(OpenSSL::SSL::SSLError){
       http.request_get("/") {|res| }
     }
-    re_msg = /\ASSL_connect returned=1 errno=0 |SSL_CTX_set_max_proto_version/
+    re_msg = /\ASSL_connect returned=1 errno=0 |SSL_CTX_set_max_proto_version|No appropriate protocol/
     assert_match(re_msg, ex.message)
   end
 
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]