Luce packages
LuceLuce BaseLuciaOS

dymokomi/luce-browser-engine

Source of release 0.6.1

0.6.1 / src / web / external / lib_http / status.lucb

#==============================================================================================
#
#   status - HTTP status codes' reason phrases
#
#   DESCRIPTION:
#       Port of Libraries/LibHTTP/Status.h (lines 14-77).
#
#       Copyright (c) 2018-2020, Andreas Kling <andreas@ladybird.org>
#       Copyright (c) 2022, the SerenityOS developers.
#       SPDX-License-Identifier: BSD-2-Clause
#
#==============================================================================================

## Ported from Libraries/LibHTTP/Status.h:14 HTTP::reason_phrase_for_code.
pub func http_reason_phrase_for_code(code: u32) -> ak.StringView:
    assert(code >= 100 and code <= 599)

    match code:
        100: return ak.sv("Continue")
        101: return ak.sv("Switching Protocols")
        200: return ak.sv("OK")
        201: return ak.sv("Created")
        202: return ak.sv("Accepted")
        203: return ak.sv("Non-Authoritative Information")
        204: return ak.sv("No Content")
        205: return ak.sv("Reset Content")
        206: return ak.sv("Partial Content")
        300: return ak.sv("Multiple Choices")
        301: return ak.sv("Moved Permanently")
        302: return ak.sv("Found")
        303: return ak.sv("See Other")
        304: return ak.sv("Not Modified")
        305: return ak.sv("Use Proxy")
        307: return ak.sv("Temporary Redirect")
        400: return ak.sv("Bad Request")
        401: return ak.sv("Unauthorized")
        402: return ak.sv("Payment Required")
        403: return ak.sv("Forbidden")
        404: return ak.sv("Not Found")
        405: return ak.sv("Method Not Allowed")
        406: return ak.sv("Not Acceptable")
        407: return ak.sv("Proxy Authentication Required")
        408: return ak.sv("Request Timeout")
        409: return ak.sv("Conflict")
        410: return ak.sv("Gone")
        411: return ak.sv("Length Required")
        412: return ak.sv("Precondition Failed")
        413: return ak.sv("Payload Too Large")
        414: return ak.sv("URI Too Long")
        415: return ak.sv("Unsupported Media Type")
        416: return ak.sv("Range Not Satisfiable")
        417: return ak.sv("Expectation Failed")
        418: return ak.sv("I'm a teapot")
        421: return ak.sv("Misdirected Request")
        422: return ak.sv("Unprocessable Content")
        423: return ak.sv("Locked")
        424: return ak.sv("Failed Dependency")
        425: return ak.sv("Too Early")
        426: return ak.sv("Upgrade Required")
        428: return ak.sv("Precondition Required")
        429: return ak.sv("Too Many Requests")
        431: return ak.sv("Request Header Fields Too Large")
        451: return ak.sv("Unavailable For Legal Reasons")
        500: return ak.sv("Internal Server Error")
        501: return ak.sv("Not Implemented")
        502: return ak.sv("Bad Gateway")
        503: return ak.sv("Service Unavailable")
        504: return ak.sv("Gateway Timeout")
        505: return ak.sv("HTTP Version Not Supported")
        _:
            # A client MUST understand the class of any status code, as indicated by the first digit, and treat an
            # unrecognized status code as being equivalent to the x00 status code of that class. (RFC 7231, section 6)
            return http_reason_phrase_for_code((code // 100) * 100)