HTTP::Status - Crystal 1.19.1

# enum HTTP::Status

##
Overview

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.

NOTE To use `Status`, you must explicitly import it with `require "http/status"`

##
Defined in:

http/status.cr

##
Enum 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`
UNAVAILABLE_FOR_LEGAL_REASONS = `451`
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`

##
Constructors

- .new(status_code : Int32) : self

  Create a new status instance with the given status code, or raise an error if the status code given is not inside 100..999.

##
Instance Method Summary

- #accepted?

  Returns `true` if this enum value equals `ACCEPTED`

- #already_reported?

  Returns `true` if this enum value equals `ALREADY_REPORTED`

- #bad_gateway?

  Returns `true` if this enum value equals `BAD_GATEWAY`

- #bad_request?

  Returns `true` if this enum value equals `BAD_REQUEST`

- #client_error? : Bool

  Returns `true` if the response status code is between 400 and 499.

- #code : Int32

  Returns the number that represents the HTTP status code.

- #conflict?

  Returns `true` if this enum value equals `CONFLICT`

- #continue?

  Returns `true` if this enum value equals `CONTINUE`

- #created?

  Returns `true` if this enum value equals `CREATED`

- #description : String | Nil

  Returns the default status description of the given HTTP status code.

- #early_hints?

  Returns `true` if this enum value equals `EARLY_HINTS`

- #expectation_failed?

  Returns `true` if this enum value equals `EXPECTATION_FAILED`

- #failed_dependency?

  Returns `true` if this enum value equals `FAILED_DEPENDENCY`

- #forbidden?

  Returns `true` if this enum value equals `FORBIDDEN`

- #found?

  Returns `true` if this enum value equals `FOUND`

- #gateway_timeout?

  Returns `true` if this enum value equals `GATEWAY_TIMEOUT`

- #gone?

  Returns `true` if this enum value equals `GONE`

- #http_version_not_supported?

  Returns `true` if this enum value equals `HTTP_VERSION_NOT_SUPPORTED`

- #im_a_teapot?

  Returns `true` if this enum value equals `IM_A_TEAPOT`

- #im_used?

  Returns `true` if this enum value equals `IM_USED`

- #informational? : Bool

  Returns `true` if the response status code is between 100 and 199.

- #insufficient_storage?

  Returns `true` if this enum value equals `INSUFFICIENT_STORAGE`

- #internal_server_error?

  Returns `true` if this enum value equals `INTERNAL_SERVER_ERROR`

- #length_required?

  Returns `true` if this enum value equals `LENGTH_REQUIRED`

- #locked?

  Returns `true` if this enum value equals `LOCKED`

- #loop_detected?

  Returns `true` if this enum value equals `LOOP_DETECTED`

- #method_not_allowed?

  Returns `true` if this enum value equals `METHOD_NOT_ALLOWED`

- #misdirected_request?

  Returns `true` if this enum value equals `MISDIRECTED_REQUEST`

- #moved_permanently?

  Returns `true` if this enum value equals `MOVED_PERMANENTLY`

- #multi_status?

  Returns `true` if this enum value equals `MULTI_STATUS`

- #multiple_choices?

  Returns `true` if this enum value equals `MULTIPLE_CHOICES`

- #network_authentication_required?

  Returns `true` if this enum value equals `NETWORK_AUTHENTICATION_REQUIRED`

- #no_content?

  Returns `true` if this enum value equals `NO_CONTENT`

- #non_authoritative_information?

  Returns `true` if this enum value equals `NON_AUTHORITATIVE_INFORMATION`

- #not_acceptable?

  Returns `true` if this enum value equals `NOT_ACCEPTABLE`

- #not_extended?

  Returns `true` if this enum value equals `NOT_EXTENDED`

- #not_found?

  Returns `true` if this enum value equals `NOT_FOUND`

- #not_implemented?

  Returns `true` if this enum value equals `NOT_IMPLEMENTED`

- #not_modified?

  Returns `true` if this enum value equals `NOT_MODIFIED`

- #ok?

  Returns `true` if this enum value equals `OK`

- #partial_content?

  Returns `true` if this enum value equals `PARTIAL_CONTENT`

- #payload_too_large?

  Returns `true` if this enum value equals `PAYLOAD_TOO_LARGE`

- #payment_required?

  Returns `true` if this enum value equals `PAYMENT_REQUIRED`

- #permanent_redirect?

  Returns `true` if this enum value equals `PERMANENT_REDIRECT`

- #precondition_failed?

  Returns `true` if this enum value equals `PRECONDITION_FAILED`

- #precondition_required?

  Returns `true` if this enum value equals `PRECONDITION_REQUIRED`

- #processing?

  Returns `true` if this enum value equals `PROCESSING`

- #proxy_authentication_required?

  Returns `true` if this enum value equals `PROXY_AUTHENTICATION_REQUIRED`

- #range_not_satisfiable?

  Returns `true` if this enum value equals `RANGE_NOT_SATISFIABLE`

- #redirection? : Bool

  Returns `true` if the response status code is between 300 and 399.

- #request_header_fields_too_large?

  Returns `true` if this enum value equals `REQUEST_HEADER_FIELDS_TOO_LARGE`

- #request_timeout?

  Returns `true` if this enum value equals `REQUEST_TIMEOUT`

- #reset_content?

  Returns `true` if this enum value equals `RESET_CONTENT`

- #see_other?

  Returns `true` if this enum value equals `SEE_OTHER`

- #server_error? : Bool

  Returns `true` if the response status code is between 500 and 599.

- #service_unavailable?

  Returns `true` if this enum value equals `SERVICE_UNAVAILABLE`

- #success? : Bool

  Returns `true` if the response status code is between 200 and 299.

- #switch_proxy?

  Returns `true` if this enum value equals `SWITCH_PROXY`

- #switching_protocols?

  Returns `true` if this enum value equals `SWITCHING_PROTOCOLS`

- #temporary_redirect?

  Returns `true` if this enum value equals `TEMPORARY_REDIRECT`

- #too_many_requests?

  Returns `true` if this enum value equals `TOO_MANY_REQUESTS`

- #unauthorized?

  Returns `true` if this enum value equals `UNAUTHORIZED`

- #unavailable_for_legal_reasons?

  Returns `true` if this enum value equals `UNAVAILABLE_FOR_LEGAL_REASONS`

- #unprocessable_entity?

  Returns `true` if this enum value equals `UNPROCESSABLE_ENTITY`

- #unsupported_media_type?

  Returns `true` if this enum value equals `UNSUPPORTED_MEDIA_TYPE`

- #upgrade_required?

  Returns `true` if this enum value equals `UPGRADE_REQUIRED`

- #uri_too_long?

  Returns `true` if this enum value equals `URI_TOO_LONG`

- #use_proxy?

  Returns `true` if this enum value equals `USE_PROXY`

- #variant_also_negotiates?

  Returns `true` if this enum value equals `VARIANT_ALSO_NEGOTIATES`

### Instance methods inherited from struct `Enum`

&(other : self) : self &, +(other : Int) : self +, -(other : Int) : self -, <=>(other : self) <=>, ==(other : self)
==(other) ==, ^(other : self) : self ^, |(other : self) : self |, ~ : self ~, clone clone, each(& : self -> ) each, hash(hasher) hash, includes?(other : self) : Bool includes?, inspect(io : IO) : Nil inspect, to_f32 : Float32 to_f32, to_f32! : Float32 to_f32!, to_f64 : Float64 to_f64, to_f64! : Float64 to_f64!, to_i : Int32 to_i, to_i128 : Int128 to_i128, to_i128! : Int128 to_i128!, to_i16 : Int16 to_i16, to_i16! : Int16 to_i16!, to_i32 : Int32 to_i32, to_i32! : Int32 to_i32!, to_i64 : Int64 to_i64, to_i64! : Int64 to_i64!, to_i8 : Int8 to_i8, to_i8! : Int8 to_i8!, to_json(json : JSON::Builder) : Nil to_json, to_s(io : IO) : Nil
to_s : String to_s, to_u128 : UInt128 to_u128, to_u128! : UInt128 to_u128!, to_u16 : UInt16 to_u16, to_u16! : UInt16 to_u16!, to_u32 : UInt32 to_u32, to_u32! : UInt32 to_u32!, to_u64 : UInt64 to_u64, to_u64! : UInt64 to_u64!, to_u8 : UInt8 to_u8, to_u8! : UInt8 to_u8!, to_yaml(yaml : YAML::Nodes::Builder) to_yaml, value : Int value

### Constructor methods inherited from struct `Enum`

from_value(value : Int) : self from_value, new(ctx : YAML::ParseContext, node : YAML::Nodes::Node)
new(value : self)
new(pull : JSON::PullParser) : self new, parse(string : String) : self parse

### Class methods inherited from struct `Enum`

each(& : self -> ) each, from_value?(value : Int) : self | Nil from_value?, names : Array(String) names, parse?(string : String) : self | Nil parse?, valid?(value : self) : Bool valid?, values : Array(self) values

### Macros inherited from struct `Enum`

[](*values) [], flags(*values) flags

### Instance methods inherited from module `Comparable(Enum)`

<(other : T) : Bool <, <=(other : T) <=, <=>(other : T) <=>, ==(other : T) ==, >(other : T) : Bool >, >=(other : T) >=, clamp(min, max)
clamp(range : Range) clamp

### Instance methods inherited from struct `Value`

==(other : Log::Metadata::Value)
==(other : JSON::Any)
==(other : YAML::Any)
==(other) ==, dup dup

### Instance methods inherited from class `Object`

! : Bool !, !=(other) !=, !~(other) !~, ==(other) ==, ===(other : JSON::Any)
===(other : YAML::Any)
===(other) ===, =~(other) =~, as(type : Class) as, as?(type : Class) as?, class class, dup dup, hash(hasher)
hash hash, in?(collection : Object) : Bool
in?(*values : Object) : Bool in?, inspect(io : IO) : Nil
inspect : String inspect, is_a?(type : Class) : Bool is_a?, itself itself, nil? : Bool nil?, not_nil!(message)
not_nil! not_nil!, pretty_inspect(width = 79, newline = "\n", indent = 0) : String pretty_inspect, pretty_print(pp : PrettyPrint) : Nil pretty_print, responds_to?(name : Symbol) : Bool responds_to?, tap(&) tap, to_json(io : IO) : Nil
to_json : String to_json, to_pretty_json(indent : String = " ") : String
to_pretty_json(io : IO, indent : String = " ") : Nil to_pretty_json, to_s(io : IO) : Nil
to_s : String to_s, to_yaml(io : IO) : Nil
to_yaml : String to_yaml, try(&) try, unsafe_as(type : T.class) forall T unsafe_as

### Class methods inherited from class `Object`

from_json(string_or_io : String | IO, root : String)
from_json(string_or_io : String | IO) from_json, from_yaml(string_or_io : String | IO) from_yaml

### Macros inherited from class `Object`

class_getter(*names, &block) class_getter, class_getter!(*names) class_getter!, class_getter?(*names, &block) class_getter?, class_property(*names, &block) class_property, class_property!(*names) class_property!, class_property?(*names, &block) class_property?, class_setter(*names) class_setter, def_clone def_clone, def_equals(*fields) def_equals, def_equals_and_hash(*fields) def_equals_and_hash, def_hash(*fields) def_hash, delegate(*methods, to object) delegate, forward_missing_to(delegate) forward_missing_to, getter(*names, &block) getter, getter!(*names) getter!, getter?(*names, &block) getter?, property(*names, &block) property, property!(*names) property!, property?(*names, &block) property?, setter(*names) setter

##
Constructor Detail

def self.new(status_code : Int32) : self #

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)  # => HTTP::Status::CONTINUE
    HTTP::Status.new(202)  # => HTTP::Status::ACCEPTED
    HTTP::Status.new(123)  # => 123
    HTTP::Status.new(1000) # raises ArgumentError

##
Instance Method Detail

def accepted? #

Returns `true` if this enum value equals `ACCEPTED`

def already_reported? #

Returns `true` if this enum value equals `ALREADY_REPORTED`

def bad_gateway? #

Returns `true` if this enum value equals `BAD_GATEWAY`

def bad_request? #

Returns `true` if this enum value equals `BAD_REQUEST`

def 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

def code : Int32 #

Returns the number that represents the HTTP status code.

    require "http/status"

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

def conflict? #

Returns `true` if this enum value equals `CONFLICT`

def continue? #

Returns `true` if this enum value equals `CONTINUE`

def created? #

Returns `true` if this enum value equals `CREATED`

def description : String | Nil #

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"

def early_hints? #

Returns `true` if this enum value equals `EARLY_HINTS`

def expectation_failed? #

Returns `true` if this enum value equals `EXPECTATION_FAILED`

def failed_dependency? #

Returns `true` if this enum value equals `FAILED_DEPENDENCY`

def forbidden? #

Returns `true` if this enum value equals `FORBIDDEN`

def found? #

Returns `true` if this enum value equals `FOUND`

def gateway_timeout? #

Returns `true` if this enum value equals `GATEWAY_TIMEOUT`

def gone? #

Returns `true` if this enum value equals `GONE`

def http_version_not_supported? #

Returns `true` if this enum value equals `HTTP_VERSION_NOT_SUPPORTED`

def im_a_teapot? #

Returns `true` if this enum value equals `IM_A_TEAPOT`

def im_used? #

Returns `true` if this enum value equals `IM_USED`

def 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

def insufficient_storage? #

Returns `true` if this enum value equals `INSUFFICIENT_STORAGE`

def internal_server_error? #

Returns `true` if this enum value equals `INTERNAL_SERVER_ERROR`

def length_required? #

Returns `true` if this enum value equals `LENGTH_REQUIRED`

def locked? #

Returns `true` if this enum value equals `LOCKED`

def loop_detected? #

Returns `true` if this enum value equals `LOOP_DETECTED`

def method_not_allowed? #

Returns `true` if this enum value equals `METHOD_NOT_ALLOWED`

def misdirected_request? #

Returns `true` if this enum value equals `MISDIRECTED_REQUEST`

def moved_permanently? #

Returns `true` if this enum value equals `MOVED_PERMANENTLY`

def multi_status? #

Returns `true` if this enum value equals `MULTI_STATUS`

def multiple_choices? #

Returns `true` if this enum value equals `MULTIPLE_CHOICES`

def network_authentication_required? #

Returns `true` if this enum value equals `NETWORK_AUTHENTICATION_REQUIRED`

def no_content? #

Returns `true` if this enum value equals `NO_CONTENT`

def non_authoritative_information? #

Returns `true` if this enum value equals `NON_AUTHORITATIVE_INFORMATION`

def not_acceptable? #

Returns `true` if this enum value equals `NOT_ACCEPTABLE`

def not_extended? #

Returns `true` if this enum value equals `NOT_EXTENDED`

def not_found? #

Returns `true` if this enum value equals `NOT_FOUND`

def not_implemented? #

Returns `true` if this enum value equals `NOT_IMPLEMENTED`

def not_modified? #

Returns `true` if this enum value equals `NOT_MODIFIED`

def ok? #

Returns `true` if this enum value equals `OK`

def partial_content? #

Returns `true` if this enum value equals `PARTIAL_CONTENT`

def payload_too_large? #

Returns `true` if this enum value equals `PAYLOAD_TOO_LARGE`

def payment_required? #

Returns `true` if this enum value equals `PAYMENT_REQUIRED`

def permanent_redirect? #

Returns `true` if this enum value equals `PERMANENT_REDIRECT`

def precondition_failed? #

Returns `true` if this enum value equals `PRECONDITION_FAILED`

def precondition_required? #

Returns `true` if this enum value equals `PRECONDITION_REQUIRED`

def processing? #

Returns `true` if this enum value equals `PROCESSING`

def proxy_authentication_required? #

Returns `true` if this enum value equals `PROXY_AUTHENTICATION_REQUIRED`

def range_not_satisfiable? #

Returns `true` if this enum value equals `RANGE_NOT_SATISFIABLE`

def 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

def request_header_fields_too_large? #

Returns `true` if this enum value equals `REQUEST_HEADER_FIELDS_TOO_LARGE`

def request_timeout? #

Returns `true` if this enum value equals `REQUEST_TIMEOUT`

def reset_content? #

Returns `true` if this enum value equals `RESET_CONTENT`

def see_other? #

Returns `true` if this enum value equals `SEE_OTHER`

def 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

def service_unavailable? #

Returns `true` if this enum value equals `SERVICE_UNAVAILABLE`

def 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

def switch_proxy? #

Returns `true` if this enum value equals `SWITCH_PROXY`

def switching_protocols? #

Returns `true` if this enum value equals `SWITCHING_PROTOCOLS`

def temporary_redirect? #

Returns `true` if this enum value equals `TEMPORARY_REDIRECT`

def too_many_requests? #

Returns `true` if this enum value equals `TOO_MANY_REQUESTS`

def unauthorized? #

Returns `true` if this enum value equals `UNAUTHORIZED`

def unavailable_for_legal_reasons? #

Returns `true` if this enum value equals `UNAVAILABLE_FOR_LEGAL_REASONS`

def unprocessable_entity? #

Returns `true` if this enum value equals `UNPROCESSABLE_ENTITY`

def unsupported_media_type? #

Returns `true` if this enum value equals `UNSUPPORTED_MEDIA_TYPE`

def upgrade_required? #

Returns `true` if this enum value equals `UPGRADE_REQUIRED`

def uri_too_long? #

Returns `true` if this enum value equals `URI_TOO_LONG`

def use_proxy? #

Returns `true` if this enum value equals `USE_PROXY`

def variant_also_negotiates? #

Returns `true` if this enum value equals `VARIANT_ALSO_NEGOTIATES`