summary refs log tree commit
diff options
context:
space:
mode:
authorJoshua Peek <josh@joshpeek.com>2009-12-10 21:52:38 -0600
committerJoshua Peek <josh@joshpeek.com>2009-12-10 21:52:38 -0600
commit5c4bd17d791d97310667acf6b458456aa1f8af0d (patch)
treef13ffb22bc1eefaa5085a5a7f46800af66f52dda
parent0f1bd2526b3972e131dccad32c7f7ea96a675880 (diff)
downloadrack-5c4bd17d791d97310667acf6b458456aa1f8af0d.tar.gz
Reverse hash for looking up status codes by symbol
-rw-r--r--lib/rack/utils.rb8
1 files changed, 7 insertions, 1 deletions
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.