diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2022-08-30 11:17:31 +1200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-08-30 11:17:31 +1200 |
commit | ffee3c55281bf6ecf27225cb4929ad5d928f53c6 (patch) | |
tree | f998e05f28130f7a2fa6531c5539eceaaacf24c1 | |
parent | 6fc4a3225289eb2e4b60ed8b4dd250eb74c85936 (diff) | |
download | rack-ffee3c55281bf6ecf27225cb4929ad5d928f53c6.tar.gz |
Allow calling close on `rack.input`. (#1956)
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | SPEC.rdoc | 3 | ||||
-rwxr-xr-x | lib/rack/lint.rb | 5 | ||||
-rwxr-xr-x | test/spec_lint.rb | 17 |
4 files changed, 17 insertions, 10 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 198f22f2..b514ec3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ All notable changes to this project will be documented in this file. For info on - `rack.hijack?` (partial hijack) and `rack.hijack` (full hijack) are now independently optional. - `rack.hijack_io` has been removed completely. - `rack.response_finished` is an optional environment key which contains an array of callable objects that must accept `#call(env, status, headers, error)` and are invoked after the response is finished (either successfully or unsucessfully). +- It is okay to call `#close` on `rack.input` to indicate that you no longer need or care about the input. ### Removed @@ -66,6 +67,7 @@ All notable changes to this project will be documented in this file. For info on - Use lower case cookie attributes when creating cookies, and fold cookie attributes to lower case when reading cookies (specifically impacting `secure` and `httponly` attributes). ([#1849](https://github.com/rack/rack/pull/1849), [@ioquatix]) - The response array must now be mutable (non-frozen) so middleware can modify it without allocating a new Array,therefore reducing object allocations. ([#1887](https://github.com/rack/rack/pull/1887), [#1927](https://github.com/rack/rack/pull/1927), [@amatsuda], [@ioquatix]) - `rack.hijack?` (partial hijack) and `rack.hijack` (full hijack) are now independently optional. `rack.hijack_io` is no longer required/specified. ([#1939](https://github.com/rack/rack/pull/1939), [@ioquatix]) +- Allow calling close on `rack.input`. ([#1956](https://github.com/rack/rack/pull/1956), [@ioquatix]) ### Fixed @@ -166,7 +166,8 @@ The input stream must respond to +gets+, +each+, and +read+. If +buffer+ is given, then the read data will be placed into +buffer+ instead of a newly created String object. * +each+ must be called without arguments and only yield Strings. -* +close+ must never be called on the input stream. +* +close+ can be called on the input stream to indicate that the +any remaining input is not needed. === The Error Stream diff --git a/lib/rack/lint.rb b/lib/rack/lint.rb index 7baca867..547e6a1c 100755 --- a/lib/rack/lint.rb +++ b/lib/rack/lint.rb @@ -478,9 +478,10 @@ module Rack } end - ## * +close+ must never be called on the input stream. + ## * +close+ can be called on the input stream to indicate that the + ## any remaining input is not needed. def close(*args) - raise LintError, "rack.input#close must not be called" + @input.close(*args) end end diff --git a/test/spec_lint.rb b/test/spec_lint.rb index 2af47f78..054f9fde 100755 --- a/test/spec_lint.rb +++ b/test/spec_lint.rb @@ -742,14 +742,17 @@ describe Rack::Lint do }).call(env("rack.input" => eof_weirdio)) }.must_raise(Rack::Lint::LintError). message.must_match(/read\(nil\) returned nil on EOF/) + end - lambda { - Rack::Lint.new(lambda { |env| - env["rack.input"].close - [201, { "content-type" => "text/plain", "content-length" => "0" }, []] - }).call(env({})) - }.must_raise(Rack::Lint::LintError). - message.must_match(/close must not be called/) + it "can call close" do + app = lambda do |env| + env["rack.input"].close + [201, {"content-type" => "text/plain", "content-length" => "0"}, []] + end + + response = Rack::Lint.new(app).call(env({})) + + response.first.must_equal 201 end it "notice error handling errors" do |