Skip to content

Commit a868ade

Browse files
committed
status: add CONTENT_TOO_LARGE and UNPROCESSABLE_CONTENT aliases
RFC9110 changed phrases for status code 413 and 422: * 413 Payload Too Large → Content Too Large * 422 Unprocessable Entity → Unprocessable Content Introduce CONTENT_TOO_LARGE and UNPROCESSABLE_CONTENT StatusCode const items to reflect those changes and update phrases used in those status code. While at it, update phrase for status 203 to ‘Non-Authoritative Information’ (with a dash) and update all links to go to RFC 9110.
1 parent f0ba97f commit a868ade

File tree

1 file changed

+76
-52
lines changed

1 file changed

+76
-52
lines changed

src/status.rs

Lines changed: 76 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -298,13 +298,27 @@ macro_rules! status_codes {
298298
(
299299
$(
300300
$(#[$docs:meta])*
301-
($num:expr, $konst:ident, $phrase:expr);
301+
($num:expr, $name:ident $(aka $alias:ident)*, $phrase:literal);
302302
)+
303303
) => {
304304
impl StatusCode {
305+
const fn from_u16_or_panic(num: u16) -> Self {
306+
if num < 100 || 999 < num {
307+
panic!()
308+
}
309+
Self(unsafe { NonZeroU16::new_unchecked(num) })
310+
}
311+
305312
$(
306313
$(#[$docs])*
307-
pub const $konst: StatusCode = StatusCode(unsafe { NonZeroU16::new_unchecked($num) });
314+
pub const $name: StatusCode = StatusCode::from_u16_or_panic($num);
315+
$(
316+
status_codes! {
317+
@alias $alias = $name;
318+
concat!("Alias of [`", stringify!($name),
319+
"`](`Self::", stringify!($name), "`).")
320+
}
321+
)*
308322
)+
309323

310324
}
@@ -317,40 +331,47 @@ macro_rules! status_codes {
317331
_ => None
318332
}
319333
}
334+
};
335+
336+
// Work around rustc 1.49 not supporting #[doc = concat!(...)]. With newer
337+
// rustc this can be inlined.
338+
(@alias $alias:ident = $name:ident; $doc:expr) => {
339+
#[doc = $doc]
340+
pub const $alias: StatusCode = StatusCode::$name;
320341
}
321342
}
322343

323344
status_codes! {
324345
/// 100 Continue
325-
/// [[RFC7231, Section 6.2.1](https://tools.ietf.org/html/rfc7231#section-6.2.1)]
346+
/// [[RFC9110, Section 15.2.1](https://www.rfc-editor.org/rfc/rfc9110#name-100-continue)]
326347
(100, CONTINUE, "Continue");
327348
/// 101 Switching Protocols
328-
/// [[RFC7231, Section 6.2.2](https://tools.ietf.org/html/rfc7231#section-6.2.2)]
349+
/// [[RFC9110, Section 15.2.2](https://www.rfc-editor.org/rfc/rfc9110#name-101-switching-protocols)]
329350
(101, SWITCHING_PROTOCOLS, "Switching Protocols");
330351
/// 102 Processing
331352
/// [[RFC2518](https://tools.ietf.org/html/rfc2518)]
332353
(102, PROCESSING, "Processing");
333354

334355
/// 200 OK
335-
/// [[RFC7231, Section 6.3.1](https://tools.ietf.org/html/rfc7231#section-6.3.1)]
356+
/// [[RFC9110, Section 15.3.1](https://www.rfc-editor.org/rfc/rfc9110#name-200-ok)]
336357
(200, OK, "OK");
337358
/// 201 Created
338-
/// [[RFC7231, Section 6.3.2](https://tools.ietf.org/html/rfc7231#section-6.3.2)]
359+
/// [[RFC9110, Section 15.3.2](https://www.rfc-editor.org/rfc/rfc9110#name-201-created)]
339360
(201, CREATED, "Created");
340361
/// 202 Accepted
341-
/// [[RFC7231, Section 6.3.3](https://tools.ietf.org/html/rfc7231#section-6.3.3)]
362+
/// [[RFC9110, Section 15.3.3](https://www.rfc-editor.org/rfc/rfc9110#name-202-accepted)]
342363
(202, ACCEPTED, "Accepted");
343364
/// 203 Non-Authoritative Information
344-
/// [[RFC7231, Section 6.3.4](https://tools.ietf.org/html/rfc7231#section-6.3.4)]
345-
(203, NON_AUTHORITATIVE_INFORMATION, "Non Authoritative Information");
365+
/// [[RFC9110, Section 15.3.4](https://www.rfc-editor.org/rfc/rfc9110#name-203-non-authoritative-infor)]
366+
(203, NON_AUTHORITATIVE_INFORMATION, "Non-Authoritative Information");
346367
/// 204 No Content
347-
/// [[RFC7231, Section 6.3.5](https://tools.ietf.org/html/rfc7231#section-6.3.5)]
368+
/// [[RFC9110, Section 15.3.5](https://www.rfc-editor.org/rfc/rfc9110#name-204-no-content)]
348369
(204, NO_CONTENT, "No Content");
349370
/// 205 Reset Content
350-
/// [[RFC7231, Section 6.3.6](https://tools.ietf.org/html/rfc7231#section-6.3.6)]
371+
/// [[RFC9110, Section 15.3.6](https://www.rfc-editor.org/rfc/rfc9110#name-205-reset-content)]
351372
(205, RESET_CONTENT, "Reset Content");
352373
/// 206 Partial Content
353-
/// [[RFC7233, Section 4.1](https://tools.ietf.org/html/rfc7233#section-4.1)]
374+
/// [[RFC9110, Section 15.3.7](https://www.rfc-editor.org/rfc/rfc9110#name-206-partial-content)]
354375
(206, PARTIAL_CONTENT, "Partial Content");
355376
/// 207 Multi-Status
356377
/// [[RFC4918](https://tools.ietf.org/html/rfc4918)]
@@ -364,103 +385,106 @@ status_codes! {
364385
(226, IM_USED, "IM Used");
365386

366387
/// 300 Multiple Choices
367-
/// [[RFC7231, Section 6.4.1](https://tools.ietf.org/html/rfc7231#section-6.4.1)]
388+
/// [[RFC9110, Section 15.4.1](https://www.rfc-editor.org/rfc/rfc9110#name-300-multiple-choices)]
368389
(300, MULTIPLE_CHOICES, "Multiple Choices");
369390
/// 301 Moved Permanently
370-
/// [[RFC7231, Section 6.4.2](https://tools.ietf.org/html/rfc7231#section-6.4.2)]
391+
/// [[RFC9110, Section 15.4.2](https://www.rfc-editor.org/rfc/rfc9110#name-301-moved-permanently)]
371392
(301, MOVED_PERMANENTLY, "Moved Permanently");
372393
/// 302 Found
373-
/// [[RFC7231, Section 6.4.3](https://tools.ietf.org/html/rfc7231#section-6.4.3)]
394+
/// [[RFC9110, Section 15.4.3](https://www.rfc-editor.org/rfc/rfc9110#name-302-found)]
374395
(302, FOUND, "Found");
375396
/// 303 See Other
376-
/// [[RFC7231, Section 6.4.4](https://tools.ietf.org/html/rfc7231#section-6.4.4)]
397+
/// [[RFC9110, Section 15.4.4](https://www.rfc-editor.org/rfc/rfc9110#name-303-see-other)]
377398
(303, SEE_OTHER, "See Other");
378399
/// 304 Not Modified
379-
/// [[RFC7232, Section 4.1](https://tools.ietf.org/html/rfc7232#section-4.1)]
400+
/// [[RFC9110, Section 15.4.5](https://www.rfc-editor.org/rfc/rfc9110#name-304-not-modified)]
380401
(304, NOT_MODIFIED, "Not Modified");
381402
/// 305 Use Proxy
382-
/// [[RFC7231, Section 6.4.5](https://tools.ietf.org/html/rfc7231#section-6.4.5)]
403+
/// [[RFC9110, Section 15.4.6](https://www.rfc-editor.org/rfc/rfc9110#name-305-use-proxy)]
383404
(305, USE_PROXY, "Use Proxy");
384405
/// 307 Temporary Redirect
385-
/// [[RFC7231, Section 6.4.7](https://tools.ietf.org/html/rfc7231#section-6.4.7)]
406+
/// [[RFC9110, Section 15.4.8](https://www.rfc-editor.org/rfc/rfc9110#name-307-temporary-redirect)]
386407
(307, TEMPORARY_REDIRECT, "Temporary Redirect");
387408
/// 308 Permanent Redirect
388-
/// [[RFC7238](https://tools.ietf.org/html/rfc7238)]
409+
/// [[RFC9110, Section 15.4.9](https://www.rfc-editor.org/rfc/rfc9110#name-308-permanent-redirect)]
389410
(308, PERMANENT_REDIRECT, "Permanent Redirect");
390411

391412
/// 400 Bad Request
392-
/// [[RFC7231, Section 6.5.1](https://tools.ietf.org/html/rfc7231#section-6.5.1)]
413+
/// [[RFC9110, Section 15.5.1](https://www.rfc-editor.org/rfc/rfc9110#name-400-bad-request)]
393414
(400, BAD_REQUEST, "Bad Request");
394415
/// 401 Unauthorized
395-
/// [[RFC7235, Section 3.1](https://tools.ietf.org/html/rfc7235#section-3.1)]
416+
/// [[RFC9110, Section 15.5.2](https://www.rfc-editor.org/rfc/rfc9110#name-401-unauthorized)]
396417
(401, UNAUTHORIZED, "Unauthorized");
397418
/// 402 Payment Required
398-
/// [[RFC7231, Section 6.5.2](https://tools.ietf.org/html/rfc7231#section-6.5.2)]
419+
/// [[RFC9110, Section 15.5.3](https://www.rfc-editor.org/rfc/rfc9110#name-402-payment-required)]
399420
(402, PAYMENT_REQUIRED, "Payment Required");
400421
/// 403 Forbidden
401-
/// [[RFC7231, Section 6.5.3](https://tools.ietf.org/html/rfc7231#section-6.5.3)]
422+
/// [[RFC9110, Section 15.5.4](https://www.rfc-editor.org/rfc/rfc9110#name-403-forbidden)]
402423
(403, FORBIDDEN, "Forbidden");
403424
/// 404 Not Found
404-
/// [[RFC7231, Section 6.5.4](https://tools.ietf.org/html/rfc7231#section-6.5.4)]
425+
/// [[RFC9110, Section 15.5.5](https://www.rfc-editor.org/rfc/rfc9110#name-404-not-found)]
405426
(404, NOT_FOUND, "Not Found");
406427
/// 405 Method Not Allowed
407-
/// [[RFC7231, Section 6.5.5](https://tools.ietf.org/html/rfc7231#section-6.5.5)]
428+
/// [[RFC9110, Section 15.5.6](https://www.rfc-editor.org/rfc/rfc9110#name-405-method-not-allowed)]
408429
(405, METHOD_NOT_ALLOWED, "Method Not Allowed");
409430
/// 406 Not Acceptable
410-
/// [[RFC7231, Section 6.5.6](https://tools.ietf.org/html/rfc7231#section-6.5.6)]
431+
/// [[RFC9110, Section 15.5.7](https://www.rfc-editor.org/rfc/rfc9110#name-406-not-acceptable)]
411432
(406, NOT_ACCEPTABLE, "Not Acceptable");
412433
/// 407 Proxy Authentication Required
413-
/// [[RFC7235, Section 3.2](https://tools.ietf.org/html/rfc7235#section-3.2)]
434+
/// [[RFC9110, Section 15.5.8](https://www.rfc-editor.org/rfc/rfc9110#name-407-proxy-authentication-re)]
414435
(407, PROXY_AUTHENTICATION_REQUIRED, "Proxy Authentication Required");
415436
/// 408 Request Timeout
416-
/// [[RFC7231, Section 6.5.7](https://tools.ietf.org/html/rfc7231#section-6.5.7)]
437+
/// [[RFC9110, Section 15.5.9](https://www.rfc-editor.org/rfc/rfc9110#name-408-request-timeout)]
417438
(408, REQUEST_TIMEOUT, "Request Timeout");
418439
/// 409 Conflict
419-
/// [[RFC7231, Section 6.5.8](https://tools.ietf.org/html/rfc7231#section-6.5.8)]
440+
/// [[RFC9110, Section 15.5.10](https://www.rfc-editor.org/rfc/rfc9110#name-409-conflict)]
420441
(409, CONFLICT, "Conflict");
421442
/// 410 Gone
422-
/// [[RFC7231, Section 6.5.9](https://tools.ietf.org/html/rfc7231#section-6.5.9)]
443+
/// [[RFC9110, Section 15.5.11](https://www.rfc-editor.org/rfc/rfc9110#name-410-gone)]
423444
(410, GONE, "Gone");
424445
/// 411 Length Required
425-
/// [[RFC7231, Section 6.5.10](https://tools.ietf.org/html/rfc7231#section-6.5.10)]
446+
/// [[RFC9110, Section 15.5.12](https://www.rfc-editor.org/rfc/rfc9110#name-411-length-required)]
426447
(411, LENGTH_REQUIRED, "Length Required");
427448
/// 412 Precondition Failed
428-
/// [[RFC7232, Section 4.2](https://tools.ietf.org/html/rfc7232#section-4.2)]
449+
/// [[RFC9110, Section 15.5.13](https://www.rfc-editor.org/rfc/rfc9110#name-412-precondition-failed)]
429450
(412, PRECONDITION_FAILED, "Precondition Failed");
430-
/// 413 Payload Too Large
431-
/// [[RFC7231, Section 6.5.11](https://tools.ietf.org/html/rfc7231#section-6.5.11)]
432-
(413, PAYLOAD_TOO_LARGE, "Payload Too Large");
451+
/// 413 Content Too Large
452+
/// [[RFC9110, Section 15.5.14](https://www.rfc-editor.org/rfc/rfc9110#name-413-content-too-large)]
453+
///
454+
/// Prior to RFC9110 phrase for this status was ‘Payload Too Large’.
455+
(413, CONTENT_TOO_LARGE aka PAYLOAD_TOO_LARGE, "Content Too Large");
433456
/// 414 URI Too Long
434-
/// [[RFC7231, Section 6.5.12](https://tools.ietf.org/html/rfc7231#section-6.5.12)]
457+
/// [[RFC9110, Section 15.5.15](https://www.rfc-editor.org/rfc/rfc9110#name-414-uri-too-long)]
435458
(414, URI_TOO_LONG, "URI Too Long");
436459
/// 415 Unsupported Media Type
437-
/// [[RFC7231, Section 6.5.13](https://tools.ietf.org/html/rfc7231#section-6.5.13)]
460+
/// [[RFC9110, Section 15.5.16](https://www.rfc-editor.org/rfc/rfc9110#name-415-unsupported-media-type)]
438461
(415, UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type");
439462
/// 416 Range Not Satisfiable
440-
/// [[RFC7233, Section 4.4](https://tools.ietf.org/html/rfc7233#section-4.4)]
463+
/// [[RFC9110, Section 15.5.17](https://www.rfc-editor.org/rfc/rfc9110#name-416-range-not-satisfiable)]
441464
(416, RANGE_NOT_SATISFIABLE, "Range Not Satisfiable");
442465
/// 417 Expectation Failed
443-
/// [[RFC7231, Section 6.5.14](https://tools.ietf.org/html/rfc7231#section-6.5.14)]
466+
/// [[RFC9110, Section 15.5.18](https://www.rfc-editor.org/rfc/rfc9110#name-417-expectation-failed)]
444467
(417, EXPECTATION_FAILED, "Expectation Failed");
445468
/// 418 I'm a teapot
446469
/// [curiously not registered by IANA but [RFC2324](https://tools.ietf.org/html/rfc2324)]
447470
(418, IM_A_TEAPOT, "I'm a teapot");
448471

449472
/// 421 Misdirected Request
450-
/// [RFC7540, Section 9.1.2](http://tools.ietf.org/html/rfc7540#section-9.1.2)
473+
/// [[RFC9110, Section 15.5.20](https://www.rfc-editor.org/rfc/rfc9110#name-421-misdirected-request)]
451474
(421, MISDIRECTED_REQUEST, "Misdirected Request");
452-
/// 422 Unprocessable Entity
453-
/// [[RFC4918](https://tools.ietf.org/html/rfc4918)]
454-
(422, UNPROCESSABLE_ENTITY, "Unprocessable Entity");
475+
/// 422 Unprocessable Content
476+
/// [[RFC9110, Section 15.5.21](https://www.rfc-editor.org/rfc/rfc9110#name-422-unprocessable-content)]
477+
///
478+
/// Prior to RFC9110 phrase for this status was ‘Unprocessable Entity’.
479+
(422, UNPROCESSABLE_CONTENT aka UNPROCESSABLE_ENTITY, "Unprocessable Content");
455480
/// 423 Locked
456481
/// [[RFC4918](https://tools.ietf.org/html/rfc4918)]
457482
(423, LOCKED, "Locked");
458483
/// 424 Failed Dependency
459484
/// [[RFC4918](https://tools.ietf.org/html/rfc4918)]
460485
(424, FAILED_DEPENDENCY, "Failed Dependency");
461-
462486
/// 426 Upgrade Required
463-
/// [[RFC7231, Section 6.5.15](https://tools.ietf.org/html/rfc7231#section-6.5.15)]
487+
/// [[RFC9110, Section 15.5.22](https://www.rfc-editor.org/rfc/rfc9110#name-426-upgrade-required)]
464488
(426, UPGRADE_REQUIRED, "Upgrade Required");
465489

466490
/// 428 Precondition Required
@@ -479,22 +503,22 @@ status_codes! {
479503
(451, UNAVAILABLE_FOR_LEGAL_REASONS, "Unavailable For Legal Reasons");
480504

481505
/// 500 Internal Server Error
482-
/// [[RFC7231, Section 6.6.1](https://tools.ietf.org/html/rfc7231#section-6.6.1)]
506+
/// [[RFC9110, Section 15.6.1](https://www.rfc-editor.org/rfc/rfc9110#name-500-internal-server-error)]
483507
(500, INTERNAL_SERVER_ERROR, "Internal Server Error");
484508
/// 501 Not Implemented
485-
/// [[RFC7231, Section 6.6.2](https://tools.ietf.org/html/rfc7231#section-6.6.2)]
509+
/// [[RFC9110, Section 15.6.2](https://www.rfc-editor.org/rfc/rfc9110#name-501-not-implemented)]
486510
(501, NOT_IMPLEMENTED, "Not Implemented");
487511
/// 502 Bad Gateway
488-
/// [[RFC7231, Section 6.6.3](https://tools.ietf.org/html/rfc7231#section-6.6.3)]
512+
/// [[RFC9110, Section 15.6.3](https://www.rfc-editor.org/rfc/rfc9110#name-502-bad-gateway)]
489513
(502, BAD_GATEWAY, "Bad Gateway");
490514
/// 503 Service Unavailable
491-
/// [[RFC7231, Section 6.6.4](https://tools.ietf.org/html/rfc7231#section-6.6.4)]
515+
/// [[RFC9110, Section 15.6.4](https://www.rfc-editor.org/rfc/rfc9110#name-503-service-unavailable)]
492516
(503, SERVICE_UNAVAILABLE, "Service Unavailable");
493517
/// 504 Gateway Timeout
494-
/// [[RFC7231, Section 6.6.5](https://tools.ietf.org/html/rfc7231#section-6.6.5)]
518+
/// [[RFC9110, Section 15.6.5](https://www.rfc-editor.org/rfc/rfc9110#name-504-gateway-timeout)]
495519
(504, GATEWAY_TIMEOUT, "Gateway Timeout");
496520
/// 505 HTTP Version Not Supported
497-
/// [[RFC7231, Section 6.6.6](https://tools.ietf.org/html/rfc7231#section-6.6.6)]
521+
/// [[RFC9110, Section 15.6.6](https://www.rfc-editor.org/rfc/rfc9110#name-505-http-version-not-suppor)]
498522
(505, HTTP_VERSION_NOT_SUPPORTED, "HTTP Version Not Supported");
499523
/// 506 Variant Also Negotiates
500524
/// [[RFC2295](https://tools.ietf.org/html/rfc2295)]

0 commit comments

Comments
 (0)