@@ -302,25 +302,41 @@ macro_rules! status_codes {
302
302
(
303
303
$(
304
304
$( #[ $docs: meta] ) *
305
- ( $num: expr, $konst : ident, $phrase: expr ) ;
305
+ ( $num: expr, $name : ident $ ( aka $alias : ident ) * , $phrase: literal ) ;
306
306
) +
307
307
) => {
308
308
impl StatusCode {
309
309
$(
310
310
$( #[ $docs] ) *
311
- pub const $konst: StatusCode = StatusCode ( unsafe { NonZeroU16 :: new_unchecked( $num) } ) ;
311
+ pub const $name: StatusCode = StatusCode ( unsafe { NonZeroU16 :: new_unchecked( $num) } ) ;
312
+ $(
313
+ status_codes! {
314
+ @alias $alias = $name;
315
+ concat!( "Alias of [`" , stringify!( $name) ,
316
+ "`](`Self::" , stringify!( $name) , "`)." )
317
+ }
318
+ ) *
312
319
) +
313
320
314
321
}
315
322
316
323
fn canonical_reason( num: u16 ) -> Option <& ' static str > {
317
324
match num {
325
+ // Make sure none of the numbers are < 100 or > 999.
326
+ 0 ..=99 | 1000 ..=u16 :: MAX => None ,
318
327
$(
319
328
$num => Some ( $phrase) ,
320
329
) +
321
330
_ => None
322
331
}
323
332
}
333
+ } ;
334
+
335
+ // Work around rustc 1.49 not supporting #[doc = concat!(...)]. With newer
336
+ // rustc this can be inlined.
337
+ ( @alias $alias: ident = $name: ident; $doc: expr) => {
338
+ #[ doc = $doc]
339
+ pub const $alias: StatusCode = StatusCode :: $name;
324
340
}
325
341
}
326
342
@@ -346,7 +362,7 @@ status_codes! {
346
362
( 202 , ACCEPTED , "Accepted" ) ;
347
363
/// 203 Non-Authoritative Information
348
364
/// [[RFC9110, Section 15.3.4](https://datatracker.ietf.org/doc/html/rfc9110#section-15.3.4)]
349
- ( 203 , NON_AUTHORITATIVE_INFORMATION , "Non Authoritative Information" ) ;
365
+ ( 203 , NON_AUTHORITATIVE_INFORMATION , "Non- Authoritative Information" ) ;
350
366
/// 204 No Content
351
367
/// [[RFC9110, Section 15.3.5](https://datatracker.ietf.org/doc/html/rfc9110#section-15.3.5)]
352
368
( 204 , NO_CONTENT , "No Content" ) ;
@@ -431,9 +447,11 @@ status_codes! {
431
447
/// 412 Precondition Failed
432
448
/// [[RFC9110, Section 15.5.13](https://datatracker.ietf.org/doc/html/rfc9110#section-15.5.13)]
433
449
( 412 , PRECONDITION_FAILED , "Precondition Failed" ) ;
434
- /// 413 Payload Too Large
450
+ /// 413 Content Too Large
435
451
/// [[RFC9110, Section 15.5.14](https://datatracker.ietf.org/doc/html/rfc9110#section-15.5.14)]
436
- ( 413 , PAYLOAD_TOO_LARGE , "Payload Too Large" ) ;
452
+ ///
453
+ /// Prior to RFC9110 phrase for this status was ‘Payload Too Large’.
454
+ ( 413 , CONTENT_TOO_LARGE aka PAYLOAD_TOO_LARGE , "Content Too Large" ) ;
437
455
/// 414 URI Too Long
438
456
/// [[RFC9110, Section 15.5.15](https://datatracker.ietf.org/doc/html/rfc9110#section-15.5.15)]
439
457
( 414 , URI_TOO_LONG , "URI Too Long" ) ;
@@ -453,9 +471,11 @@ status_codes! {
453
471
/// 421 Misdirected Request
454
472
/// [[RFC9110, Section 15.5.20](https://datatracker.ietf.org/doc/html/rfc9110#section-15.5.20)]
455
473
( 421 , MISDIRECTED_REQUEST , "Misdirected Request" ) ;
456
- /// 422 Unprocessable Entity
474
+ /// 422 Unprocessable Content
457
475
/// [[RFC9110, Section 15.5.21](https://datatracker.ietf.org/doc/html/rfc9110#section-15.5.21)]
458
- ( 422 , UNPROCESSABLE_ENTITY , "Unprocessable Entity" ) ;
476
+ ///
477
+ /// Prior to RFC9110 phrase for this status was ‘Unprocessable Entity’.
478
+ ( 422 , UNPROCESSABLE_CONTENT aka UNPROCESSABLE_ENTITY , "Unprocessable Content" ) ;
459
479
/// 423 Locked
460
480
/// [[RFC4918, Section 11.3](https://datatracker.ietf.org/doc/html/rfc4918#section-11.3)]
461
481
( 423 , LOCKED , "Locked" ) ;
0 commit comments