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
Fix response status usage - convert it with to_i method #1644
Conversation
Actually I am thinking about general approach in tests to ensure middleware follow the specification and use only declared interface of response status, headers and body. For instance in the tests all the applications can wrap a response with some helper and convert status, headers and body to objects which respond to declared method e.g. 'to_i' and app = lambda { |env| Rack::Lint::Response.wrap(201, { 'Content-Type' => 'text/plain' }, ["Hello, World!"]) }
module Rack
class Lint
module Response
def self.wrap(status, headers, body)
[status.to_s, headers.to_enum, body.to_enum]
end
end
end
end This is the simple implementation and it isn't strict as it could be but it's enough to catch issues with treating status as Integer, headers as Hash and body as Array. If it's reasonable approach I will be happy to create a PR and update the specs. |
I'm not sure how other maintainers feel about this, but I think in Rack 3 we should change SPEC to require the status to be an Integer instead of requiring that it can be converted to an integer. Having all middleware perform conversion to get the status is inefficient, and I can't see a significant advantage in supporting non-Integer status values. We already have a similar pull request to make the response headers be a hash (#1597). |
I agree status should be an integer, I don't know any use case that benefits from this not being the case. Any counter arguments? |
@tenderlove can we get your historical context on this? |
Honestly I think it's legacy. I agree it should just be an integer and we should fix SPEC |
@olleolleolle if you are interested to have a go at helping, this one is pretty low hanging fruit (updating the SPEC). |
- rack#1644 refers to the idea "require Status to be an Integer" - This implements that change
- rack#1644 refers to the idea "require Status to be an Integer" - This implements that change
- rack#1644 refers to the idea "require Status to be an Integer" - This implements that change
- #1644 refers to the idea "require Status to be an Integer" - This implements that change
Fixed by #1662 |
Some middleware treat response status as Integer but according to the specification it's just an object with
to_i
method which returns Integer.Changes: