From 7c03993858404a14186372da34095c26a2f09d74 Mon Sep 17 00:00:00 2001 From: Oskar Eichler <62393985+OskarEichler@users.noreply.github.com> Date: Sun, 30 Aug 2026 15:10:25 +0700 Subject: [PATCH] Skip body encoding for streaming destinations --- lib/net/http/response.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/net/http/response.rb b/lib/net/http/response.rb index fb48490..008f5d6 100644 --- a/lib/net/http/response.rb +++ b/lib/net/http/response.rb @@ -386,16 +386,18 @@ def read_body(dest = nil, &block) @read = true return if @body.nil? - case enc = @body_encoding - when Encoding, false, nil - # Encoding: force given encoding - # false/nil: do not force encoding - else - # other value: detect encoding from body - enc = detect_encoding(@body) - end + if @body.respond_to?(:force_encoding) + case enc = @body_encoding + when Encoding, false, nil + # Encoding: force given encoding + # false/nil: do not force encoding + else + # other value: detect encoding from body + enc = detect_encoding(@body) + end - @body.force_encoding(enc) if enc + @body.force_encoding(enc) if enc + end @body end @@ -753,4 +755,3 @@ def read_all dest end end -