Froze rails gems
[depot.git] / vendor / rails / actionpack / lib / action_controller / status_codes.rb
1 module ActionController
2 module StatusCodes #:nodoc:
3 # Defines the standard HTTP status codes, by integer, with their
4 # corresponding default message texts.
5 # Source: http://www.iana.org/assignments/http-status-codes
6 STATUS_CODES = {
7 100 => "Continue",
8 101 => "Switching Protocols",
9 102 => "Processing",
10
11 200 => "OK",
12 201 => "Created",
13 202 => "Accepted",
14 203 => "Non-Authoritative Information",
15 204 => "No Content",
16 205 => "Reset Content",
17 206 => "Partial Content",
18 207 => "Multi-Status",
19 226 => "IM Used",
20
21 300 => "Multiple Choices",
22 301 => "Moved Permanently",
23 302 => "Found",
24 303 => "See Other",
25 304 => "Not Modified",
26 305 => "Use Proxy",
27 307 => "Temporary Redirect",
28
29 400 => "Bad Request",
30 401 => "Unauthorized",
31 402 => "Payment Required",
32 403 => "Forbidden",
33 404 => "Not Found",
34 405 => "Method Not Allowed",
35 406 => "Not Acceptable",
36 407 => "Proxy Authentication Required",
37 408 => "Request Timeout",
38 409 => "Conflict",
39 410 => "Gone",
40 411 => "Length Required",
41 412 => "Precondition Failed",
42 413 => "Request Entity Too Large",
43 414 => "Request-URI Too Long",
44 415 => "Unsupported Media Type",
45 416 => "Requested Range Not Satisfiable",
46 417 => "Expectation Failed",
47 422 => "Unprocessable Entity",
48 423 => "Locked",
49 424 => "Failed Dependency",
50 426 => "Upgrade Required",
51
52 500 => "Internal Server Error",
53 501 => "Not Implemented",
54 502 => "Bad Gateway",
55 503 => "Service Unavailable",
56 504 => "Gateway Timeout",
57 505 => "HTTP Version Not Supported",
58 507 => "Insufficient Storage",
59 510 => "Not Extended"
60 }
61
62 # Provides a symbol-to-fixnum lookup for converting a symbol (like
63 # :created or :not_implemented) into its corresponding HTTP status
64 # code (like 200 or 501).
65 SYMBOL_TO_STATUS_CODE = STATUS_CODES.inject({}) do |hash, (code, message)|
66 hash[message.gsub(/ /, "").underscore.to_sym] = code
67 hash
68 end
69
70 # Given a status parameter, determine whether it needs to be converted
71 # to a string. If it is a fixnum, use the STATUS_CODES hash to lookup
72 # the default message. If it is a symbol, use the SYMBOL_TO_STATUS_CODE
73 # hash to convert it.
74 def interpret_status(status)
75 case status
76 when Fixnum then
77 "#{status} #{STATUS_CODES[status]}".strip
78 when Symbol then
79 interpret_status(SYMBOL_TO_STATUS_CODE[status] ||
80 "500 Unknown Status #{status.inspect}")
81 else
82 status.to_s
83 end
84 end
85 private :interpret_status
86
87 end
88 end