nahi / httpclient

'httpclient' gives something like the functionality of libwww-perl (LWP) in Ruby.
https://github.com/nahi/httpclient
701 stars 290 forks source link

Fix frozen string error in Ruby 3.4.0-preview1 #459

Closed ybiquitous closed 4 months ago

ybiquitous commented 4 months ago

This change fixed a frozen string error with the --enable-frozen-string-literal in Ruby 3.4.0-preview1. See the reproduction below (note that the Addressable gem is needed):

$ bundle install
...
$ bundle add addressable
...
$ RUBYOPT='--enable-frozen-string-literal -I lib -r httpclient' bundle exec ruby -e 'p HTTPClient'
/work/lib/httpclient/util.rb:71:in 'HTTPClient::Util::AddressableURI#authority': can't modify frozen String: "" (FrozenError)
    from /usr/local/bundle/gems/addressable-2.8.6/lib/addressable/uri.rb:2350:in 'Addressable::URI#to_s'
    from /usr/local/bundle/gems/addressable-2.8.6/lib/addressable/uri.rb:863:in 'Addressable::URI#initialize'
    from /usr/local/bundle/gems/addressable-2.8.6/lib/addressable/uri.rb:165:in 'Class#new'
    from /usr/local/bundle/gems/addressable-2.8.6/lib/addressable/uri.rb:165:in 'Addressable::URI.parse'
    from /work/lib/httpclient/util.rb:154:in 'HTTPClient::Util.urify'
    from /work/lib/httpclient/http.rb:195:in '<class:Headers>'
    from /work/lib/httpclient/http.rb:104:in '<class:Message>'
    from /work/lib/httpclient/http.rb:98:in '<module:HTTP>'
    from /work/lib/httpclient/http.rb:19:in '<top (required)>'
    from <internal:/usr/local/lib/ruby/3.4.0+0/rubygems/core_ext/kernel_require.rb>:136:in 'Kernel#require'
    from <internal:/usr/local/lib/ruby/3.4.0+0/rubygems/core_ext/kernel_require.rb>:136:in 'Kernel#require'
    from /work/lib/httpclient/session.rb:23:in '<top (required)>'
    from <internal:/usr/local/lib/ruby/3.4.0+0/rubygems/core_ext/kernel_require.rb>:136:in 'Kernel#require'
    from <internal:/usr/local/lib/ruby/3.4.0+0/rubygems/core_ext/kernel_require.rb>:136:in 'Kernel#require'
    from /work/lib/httpclient.rb:17:in '<top (required)>'
    from <internal:/usr/local/lib/ruby/3.4.0+0/rubygems/core_ext/kernel_require.rb>:136:in 'Kernel#require'
    from <internal:/usr/local/lib/ruby/3.4.0+0/rubygems/core_ext/kernel_require.rb>:136:in 'Kernel#require'

Ref https://www.ruby-lang.org/en/news/2024/05/16/ruby-3-4-0-preview1-released/

ybiquitous commented 4 months ago

Oops. I didn't notice that this PR duplicates with #398. Sorry. 🙇🏼