diff --git a/Gemfile.lock b/Gemfile.lock index 19efaa5d98..4e1c049ac0 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -413,7 +413,7 @@ GEM pg (>= 1.1, < 2.0) raabro (1.4.0) racc (1.8.0) - rack (3.0.11) + rack (3.1.3) rack-cache (1.15.0) rack (>= 0.4) rack-session (2.0.0) diff --git a/actionpack/lib/action_dispatch/http/request.rb b/actionpack/lib/action_dispatch/http/request.rb index 6b99e29c82..92b748ddcf 100644 --- a/actionpack/lib/action_dispatch/http/request.rb +++ b/actionpack/lib/action_dispatch/http/request.rb @@ -340,7 +340,6 @@ def server_software def raw_post unless has_header? "RAW_POST_DATA" set_header("RAW_POST_DATA", read_body_stream) - body_stream.rewind if body_stream.respond_to?(:rewind) end get_header "RAW_POST_DATA" end @@ -467,9 +466,27 @@ def default_session end def read_body_stream - body_stream.rewind if body_stream.respond_to?(:rewind) - return body_stream.read if headers.key?("Transfer-Encoding") # Read body stream until EOF if "Transfer-Encoding" is present - body_stream.read(content_length) + reset_stream(body_stream) do + if headers.key?("Transfer-Encoding") + body_stream.read # Read body stream until EOF if "Transfer-Encoding" is present + else + body_stream.read(content_length) + end + end + end + + def reset_stream(body_stream) + if body_stream.respond_to?(:rewind) + body_stream.rewind + + content = yield + + body_stream.rewind + + content + else + yield + end end end end