[ruby/net-http] Freeze some constants to improve Ractor compatibility

Freeze `Net::HTTP::SSL_IVNAMES`, `Net::HTTPResponse::CODE_CLASS_TO_OBJ`
and `Net::HTTPResponse::CODE_TO_OBJ` to improve Ractor compatibility.

This change allows the following code to work:

    Ractor.new {
      uri = URI.parse('http://example.com')
      http = Net::HTTP.new(uri.host, uri.port)
      http.open_timeout = nil
      http.read_timeout = nil
      http.get('/index.html')
    }

https://github.com/ruby/net-http/commit/9f0f5e4b4d
This commit is contained in:
Daisuke Aritomo 2025-02-03 23:54:05 +09:00 committed by git
parent 22c09135a8
commit aa0f689bf4
2 changed files with 3 additions and 3 deletions

View File

@ -1529,7 +1529,7 @@ module Net #:nodoc:
:verify_hostname,
] # :nodoc:
SSL_IVNAMES = SSL_ATTRIBUTES.map { |a| "@#{a}".to_sym } # :nodoc:
SSL_IVNAMES = SSL_ATTRIBUTES.map { |a| "@#{a}".to_sym }.freeze # :nodoc:
# Sets or returns the path to a CA certification file in PEM format.
attr_accessor :ca_file

View File

@ -1104,7 +1104,7 @@ class Net::HTTPResponse
'3' => Net::HTTPRedirection,
'4' => Net::HTTPClientError,
'5' => Net::HTTPServerError
}
}.freeze
CODE_TO_OBJ = {
'100' => Net::HTTPContinue,
'101' => Net::HTTPSwitchProtocol,
@ -1170,5 +1170,5 @@ class Net::HTTPResponse
'508' => Net::HTTPLoopDetected,
'510' => Net::HTTPNotExtended,
'511' => Net::HTTPNetworkAuthenticationRequired,
}
}.freeze
end