diff options
| author | Kazuki Yamaguchi <k@rhe.jp> | 2025-12-13 17:30:21 +0900 |
|---|---|---|
| committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2025-12-17 15:47:43 +0900 |
| commit | b80fc8bd84d194fdab60d0aee14ce0850a366500 (patch) | |
| tree | 9b103234b8fbfaa26f72fd8cefdc254c9fee9b56 /test/net | |
| parent | fedafec78b2e6aa17a4246192a40192d7a0cf69c (diff) | |
[ruby/net-http] Freeze more constants for Ractor compatibility
Freeze Net::HTTP::SSL_ATTRIBUTES and IDEMPOTENT_METHODS_. Both constants
have been marked as :nodoc:.
Together with https://github.com/ruby/openssl/issues/521, this enables
HTTPS clients in non-main Ractors on Ruby 4.0.
https://github.com/ruby/net-http/commit/f24b3b358b
Diffstat (limited to 'test/net')
| -rw-r--r-- | test/net/http/test_http.rb | 25 | ||||
| -rw-r--r-- | test/net/http/test_https.rb | 18 |
2 files changed, 43 insertions, 0 deletions
diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index 366b4cd12c..4e7fa22756 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -1400,3 +1400,28 @@ class TestNetHTTPPartialResponse < Test::Unit::TestCase assert_raise(EOFError) {http.get('/')} end end + +class TestNetHTTPInRactor < Test::Unit::TestCase + CONFIG = { + 'host' => '127.0.0.1', + 'proxy_host' => nil, + 'proxy_port' => nil, + } + + include TestNetHTTPUtils + + def test_get + assert_ractor(<<~RUBY, require: 'net/http') + expected = #{$test_net_http_data.dump}.b + ret = Ractor.new { + host = #{config('host').dump} + port = #{config('port')} + Net::HTTP.start(host, port) { |http| + res = http.get('/') + res.body + } + }.value + assert_equal expected, ret + RUBY + end +end if defined?(Ractor) && Ractor.method_defined?(:value) diff --git a/test/net/http/test_https.rb b/test/net/http/test_https.rb index 55b9eb3170..f5b21b901f 100644 --- a/test/net/http/test_https.rb +++ b/test/net/http/test_https.rb @@ -266,6 +266,24 @@ class TestNetHTTPS < Test::Unit::TestCase assert_match(re_msg, ex.message) end + def test_ractor + assert_ractor(<<~RUBY, require: 'net/https') + expected = #{$test_net_http_data.dump}.b + ret = Ractor.new { + host = #{HOST.dump} + port = #{config('port')} + ca_cert_pem = #{CA_CERT.to_pem.dump} + cert_store = OpenSSL::X509::Store.new.tap { |s| + s.add_cert(OpenSSL::X509::Certificate.new(ca_cert_pem)) + } + Net::HTTP.start(host, port, use_ssl: true, cert_store: cert_store) { |http| + res = http.get('/') + res.body + } + }.value + assert_equal expected, ret + RUBY + end if defined?(Ractor) && Ractor.method_defined?(:value) end class TestNetHTTPSIdentityVerifyFailure < Test::Unit::TestCase |
