Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow calling close on rack.input. #1956

Merged
merged 3 commits into from Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion SPEC.rdoc
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions lib/rack/lint.rb
Expand Up @@ -478,9 +478,10 @@ def each(*args)
}
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

Expand Down
8 changes: 0 additions & 8 deletions test/spec_lint.rb
Expand Up @@ -742,14 +742,6 @@ def each
}).call(env("rack.input" => eof_weirdio))
}.must_raise(Rack::Lint::LintError).
message.must_match(/read\(nil\) returned nil on EOF/)

ioquatix marked this conversation as resolved.
Show resolved Hide resolved
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/)
end

it "notice error handling errors" do
Expand Down