From 5c4bd17d791d97310667acf6b458456aa1f8af0d Mon Sep 17 00:00:00 2001 From: Joshua Peek Date: Thu, 10 Dec 2009 21:52:38 -0600 Subject: Reverse hash for looking up status codes by symbol --- lib/rack/utils.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/rack/utils.rb b/lib/rack/utils.rb index 46362bab..333d8bf5 100644 --- a/lib/rack/utils.rb +++ b/lib/rack/utils.rb @@ -27,7 +27,7 @@ module Rack module_function :unescape DEFAULT_SEP = /[&;] */n - + # Stolen from Mongrel, with some small modifications: # Parses a query string by breaking it up at the '&' # and ';' characters. You can also use this to parse @@ -394,6 +394,12 @@ module Rack # Responses with HTTP status codes that should not have an entity body STATUS_WITH_NO_ENTITY_BODY = Set.new((100..199).to_a << 204 << 304) + SYMBOL_TO_STATUS_CODE = HTTP_STATUS_CODES.inject({}) { |hash, (code, message)| + hash[message.downcase.gsub(/\s|-/, '_').to_sym] = code + hash + } + + # A multipart form data parser, adapted from IOWA. # # Usually, Rack::Request#POST takes care of calling this. -- cgit v1.2.3-24-ge0c7