diff --git a/lib/http/response/status.rb b/lib/http/response/status.rb index b9c098f1..73fb3444 100644 --- a/lib/http/response/status.rb +++ b/lib/http/response/status.rb @@ -86,31 +86,31 @@ def to_s # Check if status code is informational (1XX) # @return [Boolean] def informational? - INFORMATIONAL.keys.include?(code) + 100 <= code && code < 200 end # Check if status code is successful (2XX) # @return [Boolean] def success? - SUCCESSFUL.keys.include?(code) + 200 <= code && code < 300 end # Check if status code is redirection (3XX) # @return [Boolean] def redirect? - REDIRECTION.keys.include?(code) + 300 <= code && code < 400 end # Check if status code is client error (4XX) # @return [Boolean] def client_error? - CLIENT_ERROR.keys.include?(code) + 400 <= code && code < 500 end # Check if status code is server error (5XX) # @return [Boolean] def server_error? - SERVER_ERROR.keys.include?(code) + 500 <= code && code < 600 end # Symbolized {#reason} diff --git a/lib/http/response/status/reasons.rb b/lib/http/response/status/reasons.rb index b986a886..119c53ba 100644 --- a/lib/http/response/status/reasons.rb +++ b/lib/http/response/status/reasons.rb @@ -13,13 +13,10 @@ class Status < ::Delegator # REASONS[414] # => "Request-URI Too Long" # # @return [Hash String>] - INFORMATIONAL = { + REASONS = { 100 => "Continue", 101 => "Switching Protocols", - 102 => "Processing" - }.each { |_, v| v.freeze }.freeze - - SUCCESSFUL = { + 102 => "Processing", 200 => "OK", 201 => "Created", 202 => "Accepted", @@ -29,10 +26,7 @@ class Status < ::Delegator 206 => "Partial Content", 207 => "Multi-Status", 208 => "Already Reported", - 226 => "IM Used" - }.each { |_, v| v.freeze }.freeze - - REDIRECTION = { + 226 => "IM Used", 300 => "Multiple Choices", 301 => "Moved Permanently", 302 => "Found", @@ -40,10 +34,7 @@ class Status < ::Delegator 304 => "Not Modified", 305 => "Use Proxy", 307 => "Temporary Redirect", - 308 => "Permanent Redirect" - }.each { |_, v| v.freeze }.freeze - - CLIENT_ERROR = { + 308 => "Permanent Redirect", 400 => "Bad Request", 401 => "Unauthorized", 402 => "Payment Required", @@ -70,10 +61,7 @@ class Status < ::Delegator 428 => "Precondition Required", 429 => "Too Many Requests", 431 => "Request Header Fields Too Large", - 451 => "Unavailable For Legal Reasons" - }.each { |_, v| v.freeze }.freeze - - SERVER_ERROR = { + 451 => "Unavailable For Legal Reasons", 500 => "Internal Server Error", 501 => "Not Implemented", 502 => "Bad Gateway", @@ -86,14 +74,6 @@ class Status < ::Delegator 510 => "Not Extended", 511 => "Network Authentication Required" }.each { |_, v| v.freeze }.freeze - - REASONS = [ - INFORMATIONAL, - SUCCESSFUL, - REDIRECTION, - CLIENT_ERROR, - SERVER_ERROR - ].inject(&:merge).each { |_, v| v.freeze }.freeze end end end