From 9f0f5e4b4d03ebb3039e581f53a3c86d0c54b6c0 Mon Sep 17 00:00:00 2001 From: Daisuke Aritomo Date: Mon, 3 Feb 2025 23:54:05 +0900 Subject: [PATCH] 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') } --- lib/net/http.rb | 2 +- lib/net/http/responses.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/net/http.rb b/lib/net/http.rb index 83cf46cb..047208b4 100644 --- a/lib/net/http.rb +++ b/lib/net/http.rb @@ -1529,7 +1529,7 @@ def use_ssl=(flag) :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 diff --git a/lib/net/http/responses.rb b/lib/net/http/responses.rb index 6f6fb8d0..5e2f8ce1 100644 --- a/lib/net/http/responses.rb +++ b/lib/net/http/responses.rb @@ -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