Skip to content

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

SWITCHING_PROTOCOLS = 101

PROCESSING = 102

EARLY_HINTS = 103

OK = 200

CREATED = 201

ACCEPTED = 202

NON_AUTHORITATIVE_INFORMATION = 203

NO_CONTENT = 204

RESET_CONTENT = 205

PARTIAL_CONTENT = 206

MULTI_STATUS = 207

ALREADY_REPORTED = 208

IM_USED = 226

MULTIPLE_CHOICES = 300

MOVED_PERMANENTLY = 301

FOUND = 302

SEE_OTHER = 303

NOT_MODIFIED = 304

USE_PROXY = 305

SWITCH_PROXY = 306

TEMPORARY_REDIRECT = 307

PERMANENT_REDIRECT = 308

BAD_REQUEST = 400

UNAUTHORIZED = 401

PAYMENT_REQUIRED = 402

FORBIDDEN = 403

NOT_FOUND = 404

METHOD_NOT_ALLOWED = 405

NOT_ACCEPTABLE = 406

PROXY_AUTHENTICATION_REQUIRED = 407

REQUEST_TIMEOUT = 408

CONFLICT = 409

GONE = 410

LENGTH_REQUIRED = 411

PRECONDITION_FAILED = 412

PAYLOAD_TOO_LARGE = 413

URI_TOO_LONG = 414

UNSUPPORTED_MEDIA_TYPE = 415

RANGE_NOT_SATISFIABLE = 416

EXPECTATION_FAILED = 417

IM_A_TEAPOT = 418

MISDIRECTED_REQUEST = 421

UNPROCESSABLE_ENTITY = 422

LOCKED = 423

FAILED_DEPENDENCY = 424

UPGRADE_REQUIRED = 426

PRECONDITION_REQUIRED = 428

TOO_MANY_REQUESTS = 429

REQUEST_HEADER_FIELDS_TOO_LARGE = 431

INTERNAL_SERVER_ERROR = 500

NOT_IMPLEMENTED = 501

BAD_GATEWAY = 502

SERVICE_UNAVAILABLE = 503

GATEWAY_TIMEOUT = 504

HTTP_VERSION_NOT_SUPPORTED = 505

VARIANT_ALSO_NEGOTIATES = 506

INSUFFICIENT_STORAGE = 507

LOOP_DETECTED = 508

NOT_EXTENDED = 510

NETWORK_AUTHENTICATION_REQUIRED = 511

Class methods

.new(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
View source

Methods

#accepted?

View source

#already_reported?

View source

#bad_gateway?

View source

#bad_request?

View source

#client_error? : 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
View source

#code : Int32

Returns the number that represents the HTTP status code.

require "http/status"

status = HTTP::Status::NO_CONTENT
status.code # => 204
View source

#conflict?

View source

#continue?

View source

#created?

View source

#description : 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"
View source

#early_hints?

View source

#expectation_failed?

View source

#failed_dependency?

View source

#forbidden?

View source

#found?

View source

#gateway_timeout?

View source

#gone?

View source

#http_version_not_supported?

View source

#im_a_teapot?

View source

#im_used?

View source

#informational? : 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
View source

#insufficient_storage?

View source

#internal_server_error?

View source

#length_required?

View source

#locked?

View source

#loop_detected?

View source

#method_not_allowed?

View source

#misdirected_request?

View source

#moved_permanently?

View source

#multi_status?

View source

#multiple_choices?

View source

#network_authentication_required?

View source

#no_content?

View source

#non_authoritative_information?

View source

#not_acceptable?

View source

#not_extended?

View source

#not_found?

View source

#not_implemented?

View source

#not_modified?

View source

#partial_content?

View source

#payload_too_large?

View source

#payment_required?

View source

#permanent_redirect?

View source

#precondition_failed?

View source

#precondition_required?

View source

#processing?

View source

#proxy_authentication_required?

View source

#range_not_satisfiable?

View source

#redirection? : 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
View source

#request_header_fields_too_large?

View source

#request_timeout?

View source

#reset_content?

View source

#see_other?

View source

#server_error? : 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
View source

#service_unavailable?

View source

#success? : 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
View source

#switch_proxy?

View source

#switching_protocols?

View source

#temporary_redirect?

View source

#too_many_requests?

View source

#unauthorized?

View source
View source

#unprocessable_entity?

View source

#unsupported_media_type?

View source

#upgrade_required?

View source

#uri_too_long?

View source

#use_proxy?

View source

#variant_also_negotiates?

View source