aboutsummaryrefslogblamecommitdiffstats
path: root/actionpack/lib/action_dispatch/http/status_codes.rb
blob: 3d6ee685ea8a2190cb18d7ca18c7514458dbd48f (plain) (tree)
1
2
3
4
5
6
7
8

                                  
                     
                             
                                                         
                          

                            



                                    

                                    
             
 







                                            


                                                                      
                                                                             
                                                                                    
          
            
     
   
require 'active_support/inflector'

module ActionDispatch
  module StatusCodes #:nodoc:
    STATUS_CODES = Rack::Utils::HTTP_STATUS_CODES.merge({
      102 => "Processing",
      207 => "Multi-Status",
      226 => "IM Used",
      422 => "Unprocessable Entity",
      423 => "Locked",
      424 => "Failed Dependency",
      426 => "Upgrade Required",
      507 => "Insufficient Storage",
      510 => "Not Extended"
    }).freeze

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

    # Provides a symbol-to-fixnum lookup for converting a symbol (like
    # :created or :not_implemented) into its corresponding HTTP status
    # code (like 200 or 501).
    SYMBOL_TO_STATUS_CODE = STATUS_CODES.inject({}) { |hash, (code, message)|
      hash[ActiveSupport::Inflector.underscore(message.gsub(/ /, "")).to_sym] = code
      hash
    }.freeze
  end
end