1/**
2 * Named HTTP status codes for the unstable HTTP modules.
3 *
4 * This module centralizes the mapping from literal names of the known HTTP
5 * status codes, such as `"OK"` and `"Conflict"`, to their numeric codes. Use
6 * {@link fromLiteral} to obtain a status code from a literal name instead of
7 * remembering raw numbers.
8 *
9 * @stability unstable
10 * @since 4.0.0
11 */
12
13const codeByLiteral = {
14 Continue: 100,
15 SwitchingProtocols: 101,
16 Processing: 102,
17 EarlyHints: 103,
18 OK: 200,
19 Ok: 200,
20 Created: 201,
21 Accepted: 202,
22 NonAuthoritativeInformation: 203,
23 NoContent: 204,
24 ResetContent: 205,
25 PartialContent: 206,
26 MultiStatus: 207,
27 AlreadyReported: 208,
28 ImUsed: 226,
29 MultipleChoices: 300,
30 MovedPermanently: 301,
31 Found: 302,
32 SeeOther: 303,
33 NotModified: 304,
34 TemporaryRedirect: 307,
35 PermanentRedirect: 308,
36 BadRequest: 400,
37 Unauthorized: 401,
38 PaymentRequired: 402,
39 Forbidden: 403,
40 NotFound: 404,
41 MethodNotAllowed: 405,
42 NotAcceptable: 406,
43 ProxyAuthenticationRequired: 407,
44 RequestTimeout: 408,
45 Conflict: 409,
46 Gone: 410,
47 LengthRequired: 411,
48 PreconditionFailed: 412,
49 PayloadTooLarge: 413,
50 UriTooLong: 414,
51 UnsupportedMediaType: 415,
52 RangeNotSatisfiable: 416,
53 ExpectationFailed: 417,
54 ImATeapot: 418,
55 MisdirectedRequest: 421,
56 UnprocessableEntity: 422,
57 Locked: 423,
58 FailedDependency: 424,
59 TooEarly: 425,
60 UpgradeRequired: 426,
61 PreconditionRequired: 428,
62 TooManyRequests: 429,
63 RequestHeaderFieldsTooLarge: 431,
64 UnavailableForLegalReasons: 451,
65 InternalServerError: 500,
66 NotImplemented: 501,
67 BadGateway: 502,
68 ServiceUnavailable: 503,
69 GatewayTimeout: 504,
70 HttpVersionNotSupported: 505,
71 VariantAlsoNegotiates: 506,
72 InsufficientStorage: 507,
73 LoopDetected: 508,
74 NotExtended: 510,
75 NetworkAuthenticationRequired: 511
76} as const
77
78/**
79 * Union of literal names for the known HTTP status codes.
80 *
81 * @stability unstable
82 * @category models
83 * @since 4.0.0
84 */
85export type Literal = keyof typeof codeByLiteral
86
87/**
88 * Returns the numeric HTTP status code for a literal name.
89 *
90 * **Example** (Obtaining status codes from literal names)
91 *
92 * ```ts import.meta.vitest
93 * import { HttpStatus } from "effect/http"
94 *
95 * HttpStatus.fromLiteral("OK") // => 200
96 * HttpStatus.fromLiteral("Conflict") // => 409
97 * ```
98 *
99 * @stability unstable
100 * @category constructors
101 * @since 4.0.0
102 */
103export const fromLiteral = <L extends Literal>(literal: L): (typeof codeByLiteral)[L] => codeByLiteral[literal]