Skip to content

Commit 9f0f5e4

Browse files
committed
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') }
1 parent ae6c43c commit 9f0f5e4

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

lib/net/http.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1529,7 +1529,7 @@ def use_ssl=(flag)
15291529
:verify_hostname,
15301530
] # :nodoc:
15311531

1532-
SSL_IVNAMES = SSL_ATTRIBUTES.map { |a| "@#{a}".to_sym } # :nodoc:
1532+
SSL_IVNAMES = SSL_ATTRIBUTES.map { |a| "@#{a}".to_sym }.freeze # :nodoc:
15331533

15341534
# Sets or returns the path to a CA certification file in PEM format.
15351535
attr_accessor :ca_file

lib/net/http/responses.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1104,7 +1104,7 @@ class Net::HTTPResponse
11041104
'3' => Net::HTTPRedirection,
11051105
'4' => Net::HTTPClientError,
11061106
'5' => Net::HTTPServerError
1107-
}
1107+
}.freeze
11081108
CODE_TO_OBJ = {
11091109
'100' => Net::HTTPContinue,
11101110
'101' => Net::HTTPSwitchProtocol,
@@ -1170,5 +1170,5 @@ class Net::HTTPResponse
11701170
'508' => Net::HTTPLoopDetected,
11711171
'510' => Net::HTTPNotExtended,
11721172
'511' => Net::HTTPNetworkAuthenticationRequired,
1173-
}
1173+
}.freeze
11741174
end

0 commit comments

Comments
 (0)