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

No error if invalid status_code? #1146

Closed
Aryk opened this issue Mar 1, 2017 · 2 comments
Closed

No error if invalid status_code? #1146

Aryk opened this issue Mar 1, 2017 · 2 comments

Comments

@Aryk
Copy link

Aryk commented Mar 1, 2017

Looking at Rack::Utils, I noticed:

    # Responses with HTTP status codes that should not have an entity body
    STATUS_WITH_NO_ENTITY_BODY = Set.new((100..199).to_a << 204 << 205 << 304)

    SYMBOL_TO_STATUS_CODE = Hash[*HTTP_STATUS_CODES.map { |code, message|
      [message.downcase.gsub(/\s|-|'/, '_').to_sym, code]
    }.flatten]

    def status_code(status)
      if status.is_a?(Symbol)
        SYMBOL_TO_STATUS_CODE[status] || 500
      else
        status.to_i
      end
    end
    module_function :status_code

Problem is

Rack::Utils.status_code(:not_foundd) # => 500
Rack::Utils.status_code(21345) # => 500

I propose to introduce a status_code! function that throws an error if it is invalid and does not just default to 500.

Would you guys accept a PR on that?

@nateberkopec
Copy link

See #1034

@rafaelfranca
Copy link
Collaborator

#1034 is merged now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants