Skip to content

Commit a95fd72

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 a95fd72

File tree

1 file changed

+71
-52
lines changed

1 file changed

+71
-52
lines changed

src/status.rs

+71-52
Original file line numberDiff line numberDiff line change
@@ -298,59 +298,75 @@ 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 {
305305
$(
306306
$(#[$docs])*
307-
pub const $konst: StatusCode = StatusCode(unsafe { NonZeroU16::new_unchecked($num) });
307+
pub const $name: StatusCode = StatusCode(unsafe { NonZeroU16::new_unchecked($num) });
308+
$(
309+
status_codes! {
310+
@alias $alias = $name;
311+
concat!("Alias of [`", stringify!($name),
312+
"`](`Self::", stringify!($name), "`).")
313+
}
314+
)*
308315
)+
309316

310317
}
311318

312319
fn canonical_reason(num: u16) -> Option<&'static str> {
313320
match num {
321+
// Make sure none of the numbers are < 100 or > 999.
322+
0..=99 | 1000..=u16::MAX => None,
314323
$(
315324
$num => Some($phrase),
316325
)+
317326
_ => None
318327
}
319328
}
329+
};
330+
331+
// Work around rustc 1.49 not supporting #[doc = concat!(...)]. With newer
332+
// rustc this can be inlined.
333+
(@alias $alias:ident = $name:ident; $doc:expr) => {
334+
#[doc = $doc]
335+
pub const $alias: StatusCode = StatusCode::$name;
320336
}
321337
}
322338

323339
status_codes! {
324340
/// 100 Continue
325-
/// [[RFC7231, Section 6.2.1](https://tools.ietf.org/html/rfc7231#section-6.2.1)]
341+
/// [[RFC9110, Section 15.2.1](https://www.rfc-editor.org/rfc/rfc9110#name-100-continue)]
326342
(100, CONTINUE, "Continue");
327343
/// 101 Switching Protocols
328-
/// [[RFC7231, Section 6.2.2](https://tools.ietf.org/html/rfc7231#section-6.2.2)]
344+
/// [[RFC9110, Section 15.2.2](https://www.rfc-editor.org/rfc/rfc9110#name-101-switching-protocols)]
329345
(101, SWITCHING_PROTOCOLS, "Switching Protocols");
330346
/// 102 Processing
331347
/// [[RFC2518](https://tools.ietf.org/html/rfc2518)]
332348
(102, PROCESSING, "Processing");
333349

334350
/// 200 OK
335-
/// [[RFC7231, Section 6.3.1](https://tools.ietf.org/html/rfc7231#section-6.3.1)]
351+
/// [[RFC9110, Section 15.3.1](https://www.rfc-editor.org/rfc/rfc9110#name-200-ok)]
336352
(200, OK, "OK");
337353
/// 201 Created
338-
/// [[RFC7231, Section 6.3.2](https://tools.ietf.org/html/rfc7231#section-6.3.2)]
354+
/// [[RFC9110, Section 15.3.2](https://www.rfc-editor.org/rfc/rfc9110#name-201-created)]
339355
(201, CREATED, "Created");
340356
/// 202 Accepted
341-
/// [[RFC7231, Section 6.3.3](https://tools.ietf.org/html/rfc7231#section-6.3.3)]
357+
/// [[RFC9110, Section 15.3.3](https://www.rfc-editor.org/rfc/rfc9110#name-202-accepted)]
342358
(202, ACCEPTED, "Accepted");
343359
/// 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");
360+
/// [[RFC9110, Section 15.3.4](https://www.rfc-editor.org/rfc/rfc9110#name-203-non-authoritative-infor)]
361+
(203, NON_AUTHORITATIVE_INFORMATION, "Non-Authoritative Information");
346362
/// 204 No Content
347-
/// [[RFC7231, Section 6.3.5](https://tools.ietf.org/html/rfc7231#section-6.3.5)]
363+
/// [[RFC9110, Section 15.3.5](https://www.rfc-editor.org/rfc/rfc9110#name-204-no-content)]
348364
(204, NO_CONTENT, "No Content");
349365
/// 205 Reset Content
350-
/// [[RFC7231, Section 6.3.6](https://tools.ietf.org/html/rfc7231#section-6.3.6)]
366+
/// [[RFC9110, Section 15.3.6](https://www.rfc-editor.org/rfc/rfc9110#name-205-reset-content)]
351367
(205, RESET_CONTENT, "Reset Content");
352368
/// 206 Partial Content
353-
/// [[RFC7233, Section 4.1](https://tools.ietf.org/html/rfc7233#section-4.1)]
369+
/// [[RFC9110, Section 15.3.7](https://www.rfc-editor.org/rfc/rfc9110#name-206-partial-content)]
354370
(206, PARTIAL_CONTENT, "Partial Content");
355371
/// 207 Multi-Status
356372
/// [[RFC4918](https://tools.ietf.org/html/rfc4918)]
@@ -364,103 +380,106 @@ status_codes! {
364380
(226, IM_USED, "IM Used");
365381

366382
/// 300 Multiple Choices
367-
/// [[RFC7231, Section 6.4.1](https://tools.ietf.org/html/rfc7231#section-6.4.1)]
383+
/// [[RFC9110, Section 15.4.1](https://www.rfc-editor.org/rfc/rfc9110#name-300-multiple-choices)]
368384
(300, MULTIPLE_CHOICES, "Multiple Choices");
369385
/// 301 Moved Permanently
370-
/// [[RFC7231, Section 6.4.2](https://tools.ietf.org/html/rfc7231#section-6.4.2)]
386+
/// [[RFC9110, Section 15.4.2](https://www.rfc-editor.org/rfc/rfc9110#name-301-moved-permanently)]
371387
(301, MOVED_PERMANENTLY, "Moved Permanently");
372388
/// 302 Found
373-
/// [[RFC7231, Section 6.4.3](https://tools.ietf.org/html/rfc7231#section-6.4.3)]
389+
/// [[RFC9110, Section 15.4.3](https://www.rfc-editor.org/rfc/rfc9110#name-302-found)]
374390
(302, FOUND, "Found");
375391
/// 303 See Other
376-
/// [[RFC7231, Section 6.4.4](https://tools.ietf.org/html/rfc7231#section-6.4.4)]
392+
/// [[RFC9110, Section 15.4.4](https://www.rfc-editor.org/rfc/rfc9110#name-303-see-other)]
377393
(303, SEE_OTHER, "See Other");
378394
/// 304 Not Modified
379-
/// [[RFC7232, Section 4.1](https://tools.ietf.org/html/rfc7232#section-4.1)]
395+
/// [[RFC9110, Section 15.4.5](https://www.rfc-editor.org/rfc/rfc9110#name-304-not-modified)]
380396
(304, NOT_MODIFIED, "Not Modified");
381397
/// 305 Use Proxy
382-
/// [[RFC7231, Section 6.4.5](https://tools.ietf.org/html/rfc7231#section-6.4.5)]
398+
/// [[RFC9110, Section 15.4.6](https://www.rfc-editor.org/rfc/rfc9110#name-305-use-proxy)]
383399
(305, USE_PROXY, "Use Proxy");
384400
/// 307 Temporary Redirect
385-
/// [[RFC7231, Section 6.4.7](https://tools.ietf.org/html/rfc7231#section-6.4.7)]
401+
/// [[RFC9110, Section 15.4.8](https://www.rfc-editor.org/rfc/rfc9110#name-307-temporary-redirect)]
386402
(307, TEMPORARY_REDIRECT, "Temporary Redirect");
387403
/// 308 Permanent Redirect
388-
/// [[RFC7238](https://tools.ietf.org/html/rfc7238)]
404+
/// [[RFC9110, Section 15.4.9](https://www.rfc-editor.org/rfc/rfc9110#name-308-permanent-redirect)]
389405
(308, PERMANENT_REDIRECT, "Permanent Redirect");
390406

391407
/// 400 Bad Request
392-
/// [[RFC7231, Section 6.5.1](https://tools.ietf.org/html/rfc7231#section-6.5.1)]
408+
/// [[RFC9110, Section 15.5.1](https://www.rfc-editor.org/rfc/rfc9110#name-400-bad-request)]
393409
(400, BAD_REQUEST, "Bad Request");
394410
/// 401 Unauthorized
395-
/// [[RFC7235, Section 3.1](https://tools.ietf.org/html/rfc7235#section-3.1)]
411+
/// [[RFC9110, Section 15.5.2](https://www.rfc-editor.org/rfc/rfc9110#name-401-unauthorized)]
396412
(401, UNAUTHORIZED, "Unauthorized");
397413
/// 402 Payment Required
398-
/// [[RFC7231, Section 6.5.2](https://tools.ietf.org/html/rfc7231#section-6.5.2)]
414+
/// [[RFC9110, Section 15.5.3](https://www.rfc-editor.org/rfc/rfc9110#name-402-payment-required)]
399415
(402, PAYMENT_REQUIRED, "Payment Required");
400416
/// 403 Forbidden
401-
/// [[RFC7231, Section 6.5.3](https://tools.ietf.org/html/rfc7231#section-6.5.3)]
417+
/// [[RFC9110, Section 15.5.4](https://www.rfc-editor.org/rfc/rfc9110#name-403-forbidden)]
402418
(403, FORBIDDEN, "Forbidden");
403419
/// 404 Not Found
404-
/// [[RFC7231, Section 6.5.4](https://tools.ietf.org/html/rfc7231#section-6.5.4)]
420+
/// [[RFC9110, Section 15.5.5](https://www.rfc-editor.org/rfc/rfc9110#name-404-not-found)]
405421
(404, NOT_FOUND, "Not Found");
406422
/// 405 Method Not Allowed
407-
/// [[RFC7231, Section 6.5.5](https://tools.ietf.org/html/rfc7231#section-6.5.5)]
423+
/// [[RFC9110, Section 15.5.6](https://www.rfc-editor.org/rfc/rfc9110#name-405-method-not-allowed)]
408424
(405, METHOD_NOT_ALLOWED, "Method Not Allowed");
409425
/// 406 Not Acceptable
410-
/// [[RFC7231, Section 6.5.6](https://tools.ietf.org/html/rfc7231#section-6.5.6)]
426+
/// [[RFC9110, Section 15.5.7](https://www.rfc-editor.org/rfc/rfc9110#name-406-not-acceptable)]
411427
(406, NOT_ACCEPTABLE, "Not Acceptable");
412428
/// 407 Proxy Authentication Required
413-
/// [[RFC7235, Section 3.2](https://tools.ietf.org/html/rfc7235#section-3.2)]
429+
/// [[RFC9110, Section 15.5.8](https://www.rfc-editor.org/rfc/rfc9110#name-407-proxy-authentication-re)]
414430
(407, PROXY_AUTHENTICATION_REQUIRED, "Proxy Authentication Required");
415431
/// 408 Request Timeout
416-
/// [[RFC7231, Section 6.5.7](https://tools.ietf.org/html/rfc7231#section-6.5.7)]
432+
/// [[RFC9110, Section 15.5.9](https://www.rfc-editor.org/rfc/rfc9110#name-408-request-timeout)]
417433
(408, REQUEST_TIMEOUT, "Request Timeout");
418434
/// 409 Conflict
419-
/// [[RFC7231, Section 6.5.8](https://tools.ietf.org/html/rfc7231#section-6.5.8)]
435+
/// [[RFC9110, Section 15.5.10](https://www.rfc-editor.org/rfc/rfc9110#name-409-conflict)]
420436
(409, CONFLICT, "Conflict");
421437
/// 410 Gone
422-
/// [[RFC7231, Section 6.5.9](https://tools.ietf.org/html/rfc7231#section-6.5.9)]
438+
/// [[RFC9110, Section 15.5.11](https://www.rfc-editor.org/rfc/rfc9110#name-410-gone)]
423439
(410, GONE, "Gone");
424440
/// 411 Length Required
425-
/// [[RFC7231, Section 6.5.10](https://tools.ietf.org/html/rfc7231#section-6.5.10)]
441+
/// [[RFC9110, Section 15.5.12](https://www.rfc-editor.org/rfc/rfc9110#name-411-length-required)]
426442
(411, LENGTH_REQUIRED, "Length Required");
427443
/// 412 Precondition Failed
428-
/// [[RFC7232, Section 4.2](https://tools.ietf.org/html/rfc7232#section-4.2)]
444+
/// [[RFC9110, Section 15.5.13](https://www.rfc-editor.org/rfc/rfc9110#name-412-precondition-failed)]
429445
(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");
446+
/// 413 Content Too Large
447+
/// [[RFC9110, Section 15.5.14](https://www.rfc-editor.org/rfc/rfc9110#name-413-content-too-large)]
448+
///
449+
/// Prior to RFC9110 phrase for this status was ‘Payload Too Large’.
450+
(413, CONTENT_TOO_LARGE aka PAYLOAD_TOO_LARGE, "Content Too Large");
433451
/// 414 URI Too Long
434-
/// [[RFC7231, Section 6.5.12](https://tools.ietf.org/html/rfc7231#section-6.5.12)]
452+
/// [[RFC9110, Section 15.5.15](https://www.rfc-editor.org/rfc/rfc9110#name-414-uri-too-long)]
435453
(414, URI_TOO_LONG, "URI Too Long");
436454
/// 415 Unsupported Media Type
437-
/// [[RFC7231, Section 6.5.13](https://tools.ietf.org/html/rfc7231#section-6.5.13)]
455+
/// [[RFC9110, Section 15.5.16](https://www.rfc-editor.org/rfc/rfc9110#name-415-unsupported-media-type)]
438456
(415, UNSUPPORTED_MEDIA_TYPE, "Unsupported Media Type");
439457
/// 416 Range Not Satisfiable
440-
/// [[RFC7233, Section 4.4](https://tools.ietf.org/html/rfc7233#section-4.4)]
458+
/// [[RFC9110, Section 15.5.17](https://www.rfc-editor.org/rfc/rfc9110#name-416-range-not-satisfiable)]
441459
(416, RANGE_NOT_SATISFIABLE, "Range Not Satisfiable");
442460
/// 417 Expectation Failed
443-
/// [[RFC7231, Section 6.5.14](https://tools.ietf.org/html/rfc7231#section-6.5.14)]
461+
/// [[RFC9110, Section 15.5.18](https://www.rfc-editor.org/rfc/rfc9110#name-417-expectation-failed)]
444462
(417, EXPECTATION_FAILED, "Expectation Failed");
445463
/// 418 I'm a teapot
446464
/// [curiously not registered by IANA but [RFC2324](https://tools.ietf.org/html/rfc2324)]
447465
(418, IM_A_TEAPOT, "I'm a teapot");
448466

449467
/// 421 Misdirected Request
450-
/// [RFC7540, Section 9.1.2](http://tools.ietf.org/html/rfc7540#section-9.1.2)
468+
/// [[RFC9110, Section 15.5.20](https://www.rfc-editor.org/rfc/rfc9110#name-421-misdirected-request)]
451469
(421, MISDIRECTED_REQUEST, "Misdirected Request");
452-
/// 422 Unprocessable Entity
453-
/// [[RFC4918](https://tools.ietf.org/html/rfc4918)]
454-
(422, UNPROCESSABLE_ENTITY, "Unprocessable Entity");
470+
/// 422 Unprocessable Content
471+
/// [[RFC9110, Section 15.5.21](https://www.rfc-editor.org/rfc/rfc9110#name-422-unprocessable-content)]
472+
///
473+
/// Prior to RFC9110 phrase for this status was ‘Unprocessable Entity’.
474+
(422, UNPROCESSABLE_CONTENT aka UNPROCESSABLE_ENTITY, "Unprocessable Content");
455475
/// 423 Locked
456476
/// [[RFC4918](https://tools.ietf.org/html/rfc4918)]
457477
(423, LOCKED, "Locked");
458478
/// 424 Failed Dependency
459479
/// [[RFC4918](https://tools.ietf.org/html/rfc4918)]
460480
(424, FAILED_DEPENDENCY, "Failed Dependency");
461-
462481
/// 426 Upgrade Required
463-
/// [[RFC7231, Section 6.5.15](https://tools.ietf.org/html/rfc7231#section-6.5.15)]
482+
/// [[RFC9110, Section 15.5.22](https://www.rfc-editor.org/rfc/rfc9110#name-426-upgrade-required)]
464483
(426, UPGRADE_REQUIRED, "Upgrade Required");
465484

466485
/// 428 Precondition Required
@@ -479,22 +498,22 @@ status_codes! {
479498
(451, UNAVAILABLE_FOR_LEGAL_REASONS, "Unavailable For Legal Reasons");
480499

481500
/// 500 Internal Server Error
482-
/// [[RFC7231, Section 6.6.1](https://tools.ietf.org/html/rfc7231#section-6.6.1)]
501+
/// [[RFC9110, Section 15.6.1](https://www.rfc-editor.org/rfc/rfc9110#name-500-internal-server-error)]
483502
(500, INTERNAL_SERVER_ERROR, "Internal Server Error");
484503
/// 501 Not Implemented
485-
/// [[RFC7231, Section 6.6.2](https://tools.ietf.org/html/rfc7231#section-6.6.2)]
504+
/// [[RFC9110, Section 15.6.2](https://www.rfc-editor.org/rfc/rfc9110#name-501-not-implemented)]
486505
(501, NOT_IMPLEMENTED, "Not Implemented");
487506
/// 502 Bad Gateway
488-
/// [[RFC7231, Section 6.6.3](https://tools.ietf.org/html/rfc7231#section-6.6.3)]
507+
/// [[RFC9110, Section 15.6.3](https://www.rfc-editor.org/rfc/rfc9110#name-502-bad-gateway)]
489508
(502, BAD_GATEWAY, "Bad Gateway");
490509
/// 503 Service Unavailable
491-
/// [[RFC7231, Section 6.6.4](https://tools.ietf.org/html/rfc7231#section-6.6.4)]
510+
/// [[RFC9110, Section 15.6.4](https://www.rfc-editor.org/rfc/rfc9110#name-503-service-unavailable)]
492511
(503, SERVICE_UNAVAILABLE, "Service Unavailable");
493512
/// 504 Gateway Timeout
494-
/// [[RFC7231, Section 6.6.5](https://tools.ietf.org/html/rfc7231#section-6.6.5)]
513+
/// [[RFC9110, Section 15.6.5](https://www.rfc-editor.org/rfc/rfc9110#name-504-gateway-timeout)]
495514
(504, GATEWAY_TIMEOUT, "Gateway Timeout");
496515
/// 505 HTTP Version Not Supported
497-
/// [[RFC7231, Section 6.6.6](https://tools.ietf.org/html/rfc7231#section-6.6.6)]
516+
/// [[RFC9110, Section 15.6.6](https://www.rfc-editor.org/rfc/rfc9110#name-505-http-version-not-suppor)]
498517
(505, HTTP_VERSION_NOT_SUPPORTED, "HTTP Version Not Supported");
499518
/// 506 Variant Also Negotiates
500519
/// [[RFC2295](https://tools.ietf.org/html/rfc2295)]

0 commit comments

Comments
 (0)