mirror of https://github.com/rails/rails
Fix raw_post raising when rack.input is nil
Starting in Rack 3.1, rack.input is optional, so `read_body_stream` (used by `raw_post`) can no longer call `read` unconditionally.
This commit is contained in:
parent
dcd4e10698
commit
cd3d94a48a
|
@ -1,3 +1,7 @@
|
|||
* Fix `Request#raw_post` raising `NoMethodError` when `rack.input` is `nil`.
|
||||
|
||||
*Hartley McGuire*
|
||||
|
||||
* Remove `racc` dependency by manually writing `ActionDispatch::Journey::Scanner`.
|
||||
|
||||
*Gannon McGibbon*
|
||||
|
|
|
@ -468,11 +468,13 @@ module ActionDispatch
|
|||
end
|
||||
|
||||
def read_body_stream
|
||||
reset_stream(body_stream) do
|
||||
if has_header?(TRANSFER_ENCODING)
|
||||
body_stream.read # Read body stream until EOF if "Transfer-Encoding" is present
|
||||
else
|
||||
body_stream.read(content_length)
|
||||
if body_stream
|
||||
reset_stream(body_stream) do
|
||||
if has_header?(TRANSFER_ENCODING)
|
||||
body_stream.read # Read body stream until EOF if "Transfer-Encoding" is present
|
||||
else
|
||||
body_stream.read(content_length)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1199,6 +1199,13 @@ class RequestParameters < BaseRequestTest
|
|||
assert_not_nil e.cause
|
||||
assert_equal e.cause.backtrace, e.backtrace
|
||||
end
|
||||
|
||||
test "raw_post does not raise when rack.input is nil" do
|
||||
request = stub_request
|
||||
|
||||
# "" on Rack < 3.1, nil on Rack 3.1+
|
||||
assert_predicate request.raw_post, :blank?
|
||||
end
|
||||
end
|
||||
|
||||
class RequestParameterFilter < BaseRequestTest
|
||||
|
|
Loading…
Reference in New Issue