diff --git a/lib/protocol/rack/input.rb b/lib/protocol/rack/input.rb index 90ddc48..2c2c3e3 100644 --- a/lib/protocol/rack/input.rb +++ b/lib/protocol/rack/input.rb @@ -60,10 +60,7 @@ def close(error = nil) # # @returns [Boolean] Whether the body could be rewound. def rewind - if @body and @body.respond_to?(:rewind) - # If the body is not rewindable, this will fail. - @body.rewind - + if @body&.rewind @finished = false @closed = false diff --git a/releases.md b/releases.md index d7f7c77..c903c8e 100644 --- a/releases.md +++ b/releases.md @@ -1,5 +1,9 @@ # Releases +## Unreleased + + - Respect the result of rewinding the underlying request body. + ## v0.22.1 - Rack 2 should not use `to_ary`. diff --git a/test/protocol/rack/input.rb b/test/protocol/rack/input.rb index a1e6bf0..9425a4d 100644 --- a/test/protocol/rack/input.rb +++ b/test/protocol/rack/input.rb @@ -211,4 +211,16 @@ expect(input).to be(:closed?) end end + + with "non-rewindable body" do + let(:body) {Protocol::HTTP::Body::Readable.new} + + it "does not report a successful rewind" do + expect(input.read).to be == "" + expect(input).to be(:closed?) + + expect(input.rewind).to be == false + expect(input).to be(:closed?) + end + end end