enum HTTP::Status
¶
An enum that provides additional support around HTTP status codes.
Based on Hypertext Transfer Protocol (HTTP) Status Code Registry
It provides constants for the defined HTTP status codes as well as helper methods to easily identify the type of response.
Members¶
CONTINUE = 100
¶
100
SWITCHING_PROTOCOLS = 101
¶
101
PROCESSING = 102
¶
102
EARLY_HINTS = 103
¶
103
OK = 200
¶
200
CREATED = 201
¶
201
ACCEPTED = 202
¶
202
NON_AUTHORITATIVE_INFORMATION = 203
¶
203
NO_CONTENT = 204
¶
204
RESET_CONTENT = 205
¶
205
PARTIAL_CONTENT = 206
¶
206
MULTI_STATUS = 207
¶
207
ALREADY_REPORTED = 208
¶
208
IM_USED = 226
¶
226
MULTIPLE_CHOICES = 300
¶
300
MOVED_PERMANENTLY = 301
¶
301
FOUND = 302
¶
302
SEE_OTHER = 303
¶
303
NOT_MODIFIED = 304
¶
304
USE_PROXY = 305
¶
305
SWITCH_PROXY = 306
¶
306
TEMPORARY_REDIRECT = 307
¶
307
PERMANENT_REDIRECT = 308
¶
308
BAD_REQUEST = 400
¶
400
UNAUTHORIZED = 401
¶
401
PAYMENT_REQUIRED = 402
¶
402
FORBIDDEN = 403
¶
403
NOT_FOUND = 404
¶
404
METHOD_NOT_ALLOWED = 405
¶
405
NOT_ACCEPTABLE = 406
¶
406
PROXY_AUTHENTICATION_REQUIRED = 407
¶
407
REQUEST_TIMEOUT = 408
¶
408
CONFLICT = 409
¶
409
GONE = 410
¶
410
LENGTH_REQUIRED = 411
¶
411
PRECONDITION_FAILED = 412
¶
412
PAYLOAD_TOO_LARGE = 413
¶
413
URI_TOO_LONG = 414
¶
414
UNSUPPORTED_MEDIA_TYPE = 415
¶
415
RANGE_NOT_SATISFIABLE = 416
¶
416
EXPECTATION_FAILED = 417
¶
417
IM_A_TEAPOT = 418
¶
418
MISDIRECTED_REQUEST = 421
¶
421
UNPROCESSABLE_ENTITY = 422
¶
422
LOCKED = 423
¶
423
FAILED_DEPENDENCY = 424
¶
424
UPGRADE_REQUIRED = 426
¶
426
PRECONDITION_REQUIRED = 428
¶
428
TOO_MANY_REQUESTS = 429
¶
429
REQUEST_HEADER_FIELDS_TOO_LARGE = 431
¶
431
UNAVAILABLE_FOR_LEGAL_REASONS = 451
¶
451
INTERNAL_SERVER_ERROR = 500
¶
500
NOT_IMPLEMENTED = 501
¶
501
BAD_GATEWAY = 502
¶
502
SERVICE_UNAVAILABLE = 503
¶
503
GATEWAY_TIMEOUT = 504
¶
504
HTTP_VERSION_NOT_SUPPORTED = 505
¶
505
VARIANT_ALSO_NEGOTIATES = 506
¶
506
INSUFFICIENT_STORAGE = 507
¶
507
LOOP_DETECTED = 508
¶
508
NOT_EXTENDED = 510
¶
510
NETWORK_AUTHENTICATION_REQUIRED = 511
¶
511
Class methods¶
.new(status_code : Int32)
¶
(status_code : Int32)
Create a new status instance with the given status code, or raise an error if the status code given is not inside 100..999.
require "http/status"
HTTP::Status.new(100) # => CONTINUE
HTTP::Status.new(202) # => ACCEPTED
HTTP::Status.new(123) # => 123
HTTP::Status.new(1000) # raises ArgumentError
Methods¶
#client_error? : Bool
¶
: Bool
Returns true
if the response status code is between 400 and 499.
require "http/status"
HTTP::Status::METHOD_NOT_ALLOWED.client_error? # => true
HTTP::Status::INTERNAL_SERVER_ERROR.client_error? # => false
#code : Int32
¶
: Int32
Returns the number that represents the HTTP status code.
require "http/status"
status = HTTP::Status::NO_CONTENT
status.code # => 204
#description : String?
¶
: String?
Returns the default status description of the given HTTP status code.
require "http/status"
HTTP::Status.new(123).description # => nil
HTTP::Status::NO_CONTENT.description # => "No Content"
HTTP::Status::METHOD_NOT_ALLOWED.description # => "Method Not Allowed"
HTTP::Status::INTERNAL_SERVER_ERROR.description # => "Internal Server Error"
#informational? : Bool
¶
: Bool
Returns true
if the response status code is between 100 and 199.
require "http/status"
HTTP::Status::SWITCHING_PROTOCOLS.informational? # => true
HTTP::Status::INTERNAL_SERVER_ERROR.informational? # => false
#redirection? : Bool
¶
: Bool
Returns true
if the response status code is between 300 and 399.
require "http/status"
HTTP::Status::SWITCH_PROXY.redirection? # => true
HTTP::Status::INTERNAL_SERVER_ERROR.redirection? # => false
#server_error? : Bool
¶
: Bool
Returns true
if the response status code is between 500 and 599.
require "http/status"
HTTP::Status::INTERNAL_SERVER_ERROR.server_error? # => true
HTTP::Status::METHOD_NOT_ALLOWED.server_error? # => false
#success? : Bool
¶
: Bool
Returns true
if the response status code is between 200 and 299.
require "http/status"
HTTP::Status::NO_CONTENT.success? # => true
HTTP::Status::INTERNAL_SERVER_ERROR.success? # => false