diff --git a/lib/http/response/body.rb b/lib/http/response/body.rb index 7dd97673..089be974 100644 --- a/lib/http/response/body.rb +++ b/lib/http/response/body.rb @@ -35,11 +35,18 @@ def to_s fail StateError, "body is being streamed" unless @streaming.nil? + # see issue 312 + begin + encoding = Encoding.find @encoding + rescue ArgumentError + encoding = Encoding::BINARY + end + begin @streaming = false - @contents = "".force_encoding(@encoding) + @contents = "".force_encoding(encoding) while (chunk = @client.readpartial) - @contents << chunk.force_encoding(@encoding) + @contents << chunk.force_encoding(encoding) end rescue @contents = nil