mirror of
https://github.com/ruby/ruby.git
synced 2026-01-27 04:24:23 +00:00
[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
This commit is contained in:
parent
fedafec78b
commit
b80fc8bd84
Notes:
git
2025-12-17 06:48:26 +00:00
@ -1531,7 +1531,7 @@ module Net #:nodoc:
|
||||
:verify_depth,
|
||||
:verify_mode,
|
||||
:verify_hostname,
|
||||
] # :nodoc:
|
||||
].freeze # :nodoc:
|
||||
|
||||
SSL_IVNAMES = SSL_ATTRIBUTES.map { |a| "@#{a}".to_sym }.freeze # :nodoc:
|
||||
|
||||
@ -2430,7 +2430,7 @@ module Net #:nodoc:
|
||||
|
||||
# :stopdoc:
|
||||
|
||||
IDEMPOTENT_METHODS_ = %w/GET HEAD PUT DELETE OPTIONS TRACE/ # :nodoc:
|
||||
IDEMPOTENT_METHODS_ = %w/GET HEAD PUT DELETE OPTIONS TRACE/.freeze # :nodoc:
|
||||
|
||||
def transport_request(req)
|
||||
count = 0
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user