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

SPEC: Require "status" to be Integer and >= 100 (BREAKING CHANGE) #1662

Merged
merged 1 commit into from May 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
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 @@ -6,6 +6,7 @@ All notable changes to this project will be documented in this file. For info on

### Changed

- BREAKING CHANGE: Require `status` to be an Integer. ([#1662](https://github.com/rack/rack/pull/1662), [@olleolleolle](https://github.com/olleolleolle))
- Relax validations around `Rack::Request#host` and `Rack::Request#hostname`. ([#1606](https://github.com/rack/rack/issues/1606), [@pvande](https://github.com/pvande))

### Fixed
Expand Down
4 changes: 2 additions & 2 deletions SPEC.rdoc
Expand Up @@ -246,8 +246,8 @@ if the request env has <tt>rack.hijack?</tt> <tt>true</tt>.
request pattern is intended to provide the hijacker with "raw tcp".
== The Response
=== The Status
This is an HTTP status. When parsed as integer (+to_i+), it must be
greater than or equal to 100.
This is an HTTP status. It must be an Integer greater than or equal to
100.
=== The Headers
The header must respond to +each+, and yield values of key and value.
The header keys must be Strings.
Expand Down
8 changes: 5 additions & 3 deletions lib/rack/lint.rb
Expand Up @@ -659,9 +659,11 @@ def check_hijack_response(headers, env)

## === The Status
def check_status(status)
## This is an HTTP status. When parsed as integer (+to_i+), it must be
## greater than or equal to 100.
assert("Status must be >=100 seen as integer") { status.to_i >= 100 }
## This is an HTTP status. It must be an Integer greater than or equal to
## 100.
assert("Status must be an Integer >=100") {
status.is_a?(Integer) && status >= 100
}
end

## === The Headers
Expand Down
8 changes: 0 additions & 8 deletions test/spec_content_type.rb
Expand Up @@ -44,12 +44,4 @@ def request
response[1]['Content-Type'].must_be_nil
end
end

['100', '204', '304'].each do |code|
it "not set Content-Type on #{code} responses if status is a string" do
app = lambda { |env| [code, {}, []] }
response = content_type(app, "text/html").call(request)
response[1]['Content-Type'].must_be_nil
end
end
end
11 changes: 9 additions & 2 deletions test/spec_lint.rb
Expand Up @@ -266,14 +266,21 @@ def result.name
["cc", {}, ""]
}).call(env({}))
}.must_raise(Rack::Lint::LintError).
message.must_match(/must be >=100 seen as integer/)
message.must_match(/must be an Integer >=100/)

lambda {
Rack::Lint.new(lambda { |env|
[42, {}, ""]
}).call(env({}))
}.must_raise(Rack::Lint::LintError).
message.must_match(/must be >=100 seen as integer/)
message.must_match(/must be an Integer >=100/)

lambda {
Rack::Lint.new(lambda { |env|
["200", {}, ""]
}).call(env({}))
}.must_raise(Rack::Lint::LintError).
message.must_match(/must be an Integer >=100/)
end

it "notice header errors" do
Expand Down