From 39cc6d7bcc2a2fc7189f4be2a7c4d0c8d9875f0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Roh=C3=A9e?= Date: Tue, 1 Jul 2014 01:21:53 +0200 Subject: [PATCH 1/5] RFC 2616 -> RFC 7231 Reference and quote the up to date RFC (7231) and not the deprecated (2616) one, rename some codes according to the current accepted naming. --- src/httpcommon/status.rs | 42 +++++++++++++++++----------------------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/src/httpcommon/status.rs b/src/httpcommon/status.rs index b94e2a4..9f21120 100644 --- a/src/httpcommon/status.rs +++ b/src/httpcommon/status.rs @@ -4,7 +4,7 @@ use std::cmp::{PartialEq, Eq, PartialOrd, Ord}; use std::fmt; use std::mem::transmute; -/// An HTTP status code (`Status-Code` in RFC 2616). +/// An HTTP status code (`Status-Code` in RFC 7231). /// /// This enum is absolutely exhaustive, covering all 500 possible values (100–599). /// @@ -653,13 +653,13 @@ pub enum StatusCode { /// 412 Precondition Failed PreconditionFailed = 412, /// 413 Request Entity Too Large - RequestEntityTooLarge = 413, + PayloadTooLarge = 413, /// 414 Request-URI Too Long - RequestUriTooLong = 414, + UriTooLong = 414, /// 415 Unsupported Media Type UnsupportedMediaType = 415, /// 416 Requested Range Not Satisfiable - RequestedRangeNotSatisfiable = 416, + RangeNotSatisfiable = 416, /// 417 Expectation Failed ExpectationFailed = 417, /// 418 I'm a teapot @@ -1359,10 +1359,10 @@ impl StatusCode { Gone => Some("Gone"), LengthRequired => Some("Length Required"), PreconditionFailed => Some("Precondition Failed"), - RequestEntityTooLarge => Some("Request Entity Too Large"), - RequestUriTooLong => Some("Request-URI Too Long"), + PayloadTooLarge => Some("Payload Too Large"), + UriTooLong => Some("URI Too Long"), UnsupportedMediaType => Some("Unsupported Media Type"), - RequestedRangeNotSatisfiable => Some("Requested Range Not Satisfiable"), + RangeNotSatisfiable => Some("Range Not Satisfiable"), ExpectationFailed => Some("Expectation Failed"), ImATeapot => Some("I'm a teapot"), AuthenticationTimeout => Some("Authentication Timeout"), @@ -1663,8 +1663,8 @@ impl ToPrimitive for StatusCode { /// The class of an HTTP `Status-Code`. /// -/// [RFC 2616, section 6.1.1 (Status Code and Reason -/// Phrase)](https://tools.ietf.org/html/rfc2616#section-6.1.1): +/// [RFC 7231, section 6 (Response Status Codes)] +/// (https://tools.ietf.org/html/rfc7231#section-6): /// /// > The first digit of the Status-Code defines the class of response. The /// > last two digits do not have any categorization role. @@ -1718,24 +1718,18 @@ impl StatusClass { /// assert_eq!(ClientError.default_code(), BadRequest); /// ``` /// - /// The use for this is outlined in [RFC 2616, section 6.1.1 (Status Code and Reason - /// Phrase)](https://tools.ietf.org/html/rfc2616#section-6.1.1): + /// The use for this is outlined in [RFC 7231, section 6 (Response Status Code)] + /// (https://tools.ietf.org/html/rfc7231#section-6): /// - /// > HTTP status codes are extensible. HTTP applications are not required - /// > to understand the meaning of all registered status codes, though such - /// > understanding is obviously desirable. However, applications MUST + /// > HTTP status codes are extensible. HTTP clients are not required to + /// > understand the meaning of all registered status codes, though such + /// > understanding is obviously desirable. However, a client MUST /// > understand the class of any status code, as indicated by the first - /// > digit, and treat any unrecognized response as being equivalent to the - /// > x00 status code of that class, with the exception that an - /// > unrecognized response MUST NOT be cached. For example, if an - /// > unrecognized status code of 431 is received by the client, it can - /// > safely assume that there was something wrong with its request and - /// > treat the response as if it had received a 400 status code. In such - /// > cases, user agents SHOULD present to the user the entity returned - /// > with the response, since that entity is likely to include human- - /// > readable information which will explain the unusual status. + /// > digit, and treat an unrecognized status code as being equivalent to + /// > the x00 status code of that class, with the exception that a + /// > recipient MUST NOT cache a response with an unrecognized status code. /// - /// This is demonstrated thusly (I’ll use 432 rather than 431 as 431 *is* now in use): + /// This is demonstrated thusly (I’ll use 432): /// /// ```rust /// # use httpcommon::status::{Code432, BadRequest}; From cd6363f0d29db2cfdd6ed69d03759d20d04c29ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Roh=C3=A9e?= Date: Tue, 1 Jul 2014 09:03:14 +0200 Subject: [PATCH 2/5] update the comments according to RFC 7231 too --- src/httpcommon/status.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/httpcommon/status.rs b/src/httpcommon/status.rs index 9f21120..8825422 100644 --- a/src/httpcommon/status.rs +++ b/src/httpcommon/status.rs @@ -652,13 +652,13 @@ pub enum StatusCode { LengthRequired = 411, /// 412 Precondition Failed PreconditionFailed = 412, - /// 413 Request Entity Too Large + /// 413 Payload Too Large PayloadTooLarge = 413, - /// 414 Request-URI Too Long + /// 414 URI Too Long UriTooLong = 414, /// 415 Unsupported Media Type UnsupportedMediaType = 415, - /// 416 Requested Range Not Satisfiable + /// 416 Range Not Satisfiable RangeNotSatisfiable = 416, /// 417 Expectation Failed ExpectationFailed = 417, From ccd371a4995c90ab8100f475abdb6a9f6d8fda56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Roh=C3=A9e?= Date: Tue, 1 Jul 2014 09:10:08 +0200 Subject: [PATCH 3/5] Update a RFC 2616 quote with the RFC 7231 content --- src/httpcommon/status.rs | 35 +++++++++++++++++++---------------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/src/httpcommon/status.rs b/src/httpcommon/status.rs index 8825422..ec8bc2f 100644 --- a/src/httpcommon/status.rs +++ b/src/httpcommon/status.rs @@ -1666,24 +1666,27 @@ impl ToPrimitive for StatusCode { /// [RFC 7231, section 6 (Response Status Codes)] /// (https://tools.ietf.org/html/rfc7231#section-6): /// -/// > The first digit of the Status-Code defines the class of response. The -/// > last two digits do not have any categorization role. -/// > -/// > ... +/// > The status-code element is a three-digit integer code giving the +/// > result of the attempt to understand and satisfy the request. /// > -/// > HTTP status codes are extensible. HTTP applications are not required -/// > to understand the meaning of all registered status codes, though such -/// > understanding is obviously desirable. However, applications MUST +/// > HTTP status codes are extensible. HTTP clients are not required to +/// > understand the meaning of all registered status codes, though such +/// > understanding is obviously desirable. However, a client MUST /// > understand the class of any status code, as indicated by the first -/// > digit, and treat any unrecognized response as being equivalent to the -/// > x00 status code of that class, with the exception that an -/// > unrecognized response MUST NOT be cached. For example, if an -/// > unrecognized status code of 431 is received by the client, it can -/// > safely assume that there was something wrong with its request and -/// > treat the response as if it had received a 400 status code. In such -/// > cases, user agents SHOULD present to the user the entity returned -/// > with the response, since that entity is likely to include human- -/// > readable information which will explain the unusual status. +/// > digit, and treat an unrecognized status code as being equivalent to +/// > the x00 status code of that class, with the exception that a +/// > recipient MUST NOT cache a response with an unrecognized status code. +/// > +/// > For example, if an unrecognized status code of 471 is received by a +/// > client, the client can assume that there was something wrong with its +/// > request and treat the response as if it had received a 400 (Bad +/// > Request) status code. The response message will usually contain a +/// > representation that explains the status. +/// > +/// > The first digit of the status-code defines the class of response. +/// > The last two digits do not have any categorization role. There are +/// > five values for the first digit: +/// > The first digit of the Status-Code defines the class of response. The /// /// This can be used in cases where a status code’s meaning is unknown, also, /// to get the appropriate *category* of status. From bdb0f479edf0581537f3c59441a8a91058c8d126 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Roh=C3=A9e?= Date: Tue, 1 Jul 2014 09:15:25 +0200 Subject: [PATCH 4/5] Update example to match the RFC 7231 --- src/httpcommon/status.rs | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/httpcommon/status.rs b/src/httpcommon/status.rs index ec8bc2f..1a1b547 100644 --- a/src/httpcommon/status.rs +++ b/src/httpcommon/status.rs @@ -1731,13 +1731,19 @@ impl StatusClass { /// > digit, and treat an unrecognized status code as being equivalent to /// > the x00 status code of that class, with the exception that a /// > recipient MUST NOT cache a response with an unrecognized status code. + /// > + /// > For example, if an unrecognized status code of 471 is received by a + /// > client, the client can assume that there was something wrong with its + /// > request and treat the response as if it had received a 400 (Bad + /// > Request) status code. The response message will usually contain a + /// > representation that explains the status. /// - /// This is demonstrated thusly (I’ll use 432): + /// This is demonstrated thusly (I’ll use 471): /// /// ```rust - /// # use httpcommon::status::{Code432, BadRequest}; + /// # use httpcommon::status::{Code471, BadRequest}; /// // Suppose we have received this status code. - /// let status = Code432; + /// let status = Code471; /// /// // Uh oh! Don’t know what to do with it. /// // Let’s fall back to the default: From 48c77c1df65516f70af26e3c2a03bf696464d5a3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Roh=C3=A9e?= Date: Tue, 1 Jul 2014 09:54:06 +0200 Subject: [PATCH 5/5] remove stray line --- src/httpcommon/status.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/httpcommon/status.rs b/src/httpcommon/status.rs index 1a1b547..023316a 100644 --- a/src/httpcommon/status.rs +++ b/src/httpcommon/status.rs @@ -1686,7 +1686,6 @@ impl ToPrimitive for StatusCode { /// > The first digit of the status-code defines the class of response. /// > The last two digits do not have any categorization role. There are /// > five values for the first digit: -/// > The first digit of the Status-Code defines the class of response. The /// /// This can be used in cases where a status code’s meaning is unknown, also, /// to get the appropriate *category* of status.