Skip to content

Commit

Permalink
SPEC: Require "status" to be Integer and >= 100
Browse files Browse the repository at this point in the history
  - #1644 refers to the idea "require Status to be an Integer"
  - This implements that change
  • Loading branch information
olleolleolle committed May 24, 2020
1 parent d8a95b8 commit 362d40c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
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

0 comments on commit 362d40c

Please sign in to comment.