httprb / http

HTTP (The Gem! a.k.a. http.rb) - a fast Ruby HTTP client with a chainable API, streaming support, and timeouts
MIT License
3.01k stars 321 forks source link

FrozenError on Ruby 3.0.0 #640

Closed TeroPihlaja closed 3 years ago

TeroPihlaja commented 3 years ago

http gem 3.3.0 running on Ruby 3.0.0 seems to be causing FrozenError: can't modify frozen String: "" exception in the following case:

.../gems/http-3.3.0/lib/http/response/body.rb:52:in `force_encoding'
.../gems/http-3.3.0/lib/http/response/body.rb:52:in `to_s'
.../gems/http-3.3.0/lib/http/response.rb:92:in `flush'

I was checking the reason for this error and it sseems to be caused by the following lines: https://github.com/httprb/http/blob/3-x-stable/lib/http/response/body.rb#L52

@contents   = String.new("").force_encoding(@encoding)
...
@contents << chunk.force_encoding(@encoding)

Also same pattern repeats in master so I believe that is also affected (but did not test): https://github.com/httprb/http/blob/f4fb3369d030520e981eb891fb5dd25f8e0403d2/lib/http/response/body.rb#L51

TeroPihlaja commented 3 years ago

Seems to already be fixed in 4.4.1. Closing issue.