Skip to content

Commit 7697832

Browse files
authored
Merge pull request #256 from rhenium/ky/freeze-more-constants
Freeze more constants for Ractor compatibility
2 parents ce9ac47 + f24b3b3 commit 7697832

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

lib/net/http.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1531,7 +1531,7 @@ def use_ssl=(flag)
15311531
:verify_depth,
15321532
:verify_mode,
15331533
:verify_hostname,
1534-
] # :nodoc:
1534+
].freeze # :nodoc:
15351535

15361536
SSL_IVNAMES = SSL_ATTRIBUTES.map { |a| "@#{a}".to_sym }.freeze # :nodoc:
15371537

@@ -2430,7 +2430,7 @@ def send_entity(path, data, initheader, dest, type, &block)
24302430

24312431
# :stopdoc:
24322432

2433-
IDEMPOTENT_METHODS_ = %w/GET HEAD PUT DELETE OPTIONS TRACE/ # :nodoc:
2433+
IDEMPOTENT_METHODS_ = %w/GET HEAD PUT DELETE OPTIONS TRACE/.freeze # :nodoc:
24342434

24352435
def transport_request(req)
24362436
count = 0

test/net/http/test_http.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,3 +1400,28 @@ def test_partial_response
14001400
assert_raise(EOFError) {http.get('/')}
14011401
end
14021402
end
1403+
1404+
class TestNetHTTPInRactor < Test::Unit::TestCase
1405+
CONFIG = {
1406+
'host' => '127.0.0.1',
1407+
'proxy_host' => nil,
1408+
'proxy_port' => nil,
1409+
}
1410+
1411+
include TestNetHTTPUtils
1412+
1413+
def test_get
1414+
assert_ractor(<<~RUBY, require: 'net/http')
1415+
expected = #{$test_net_http_data.dump}.b
1416+
ret = Ractor.new {
1417+
host = #{config('host').dump}
1418+
port = #{config('port')}
1419+
Net::HTTP.start(host, port) { |http|
1420+
res = http.get('/')
1421+
res.body
1422+
}
1423+
}.value
1424+
assert_equal expected, ret
1425+
RUBY
1426+
end
1427+
end if defined?(Ractor) && Ractor.method_defined?(:value)

test/net/http/test_https.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,24 @@ def test_max_version
266266
assert_match(re_msg, ex.message)
267267
end
268268

269+
def test_ractor
270+
assert_ractor(<<~RUBY, require: 'net/https')
271+
expected = #{$test_net_http_data.dump}.b
272+
ret = Ractor.new {
273+
host = #{HOST.dump}
274+
port = #{config('port')}
275+
ca_cert_pem = #{CA_CERT.to_pem.dump}
276+
cert_store = OpenSSL::X509::Store.new.tap { |s|
277+
s.add_cert(OpenSSL::X509::Certificate.new(ca_cert_pem))
278+
}
279+
Net::HTTP.start(host, port, use_ssl: true, cert_store: cert_store) { |http|
280+
res = http.get('/')
281+
res.body
282+
}
283+
}.value
284+
assert_equal expected, ret
285+
RUBY
286+
end if defined?(Ractor) && Ractor.method_defined?(:value)
269287
end
270288

271289
class TestNetHTTPSIdentityVerifyFailure < Test::Unit::TestCase

0 commit comments

Comments
 (0)