-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(headers): Introduce header!() macro, improve documentation
The new macro handles single value headers, list headers, and list headers with at least one item. It creates the item for the header and contains its documentation. The new macro allows handling more header cases in the future, it will also be possible to include tests inside the macro. BREAKING CHANGE: Removed impl_header!() and impl_list_header!() macros, use new header!() macro.
- Loading branch information
Showing
19 changed files
with
367 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,23 @@ | ||
use header::Encoding; | ||
|
||
/// The `Content-Encoding` header. | ||
/// | ||
/// This header describes the encoding of the message body. It can be | ||
/// comma-separated, including multiple encodings. | ||
/// | ||
/// ```notrust | ||
/// Content-Encoding: gzip | ||
/// ``` | ||
#[derive(Clone, PartialEq, Debug)] | ||
pub struct ContentEncoding(pub Vec<Encoding>); | ||
|
||
impl_list_header!(ContentEncoding, | ||
"Content-Encoding", | ||
Vec<Encoding>); | ||
header! { | ||
#[doc="`Content-Encoding` header, defined in"] | ||
#[doc="[RFC7231](http://tools.ietf.org/html/rfc7231#section-3.1.2.2)"] | ||
#[doc=""] | ||
#[doc="The `Content-Encoding` header field indicates what content codings"] | ||
#[doc="have been applied to the representation, beyond those inherent in the"] | ||
#[doc="media type, and thus what decoding mechanisms have to be applied in"] | ||
#[doc="order to obtain data in the media type referenced by the Content-Type"] | ||
#[doc="header field. Content-Encoding is primarily used to allow a"] | ||
#[doc="representation's data to be compressed without losing the identity of"] | ||
#[doc="its underlying media type."] | ||
#[doc=""] | ||
#[doc="# ABNF"] | ||
#[doc="```plain"] | ||
#[doc="Content-Encoding = 1#content-coding"] | ||
#[doc="```"] | ||
(ContentEncoding, "ContentEncoding") => (Encoding)+ | ||
} | ||
|
||
bench_header!(single, ContentEncoding, { vec![b"gzip".to_vec()] }); | ||
bench_header!(multiple, ContentEncoding, { vec![b"gzip, deflate".to_vec()] }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,21 @@ | ||
/// The `Content-Length` header. | ||
/// | ||
/// Simply a wrapper around a `u64`. | ||
#[derive(Copy, Clone, PartialEq, Debug)] | ||
pub struct ContentLength(pub u64); | ||
|
||
impl_header!(ContentLength, | ||
"Content-Length", | ||
u64); | ||
header! { | ||
#[doc="`Content-Length` header, defined in"] | ||
#[doc="[RFC7230](http://tools.ietf.org/html/rfc7230#section-3.3.2)"] | ||
#[doc=""] | ||
#[doc="When a message does not have a `Transfer-Encoding` header field, a"] | ||
#[doc="Content-Length header field can provide the anticipated size, as a"] | ||
#[doc="decimal number of octets, for a potential payload body. For messages"] | ||
#[doc="that do include a payload body, the Content-Length field-value"] | ||
#[doc="provides the framing information necessary for determining where the"] | ||
#[doc="body (and message) ends. For messages that do not include a payload"] | ||
#[doc="body, the Content-Length indicates the size of the selected"] | ||
#[doc="representation."] | ||
#[doc=""] | ||
#[doc="# ABNF"] | ||
#[doc="```plain"] | ||
#[doc="Content-Length = 1*DIGIT"] | ||
#[doc="```"] | ||
(ContentLength, "Content-Length") => [u64] | ||
} | ||
|
||
bench_header!(bench, ContentLength, { vec![b"42349984".to_vec()] }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,22 @@ | ||
use mime::Mime; | ||
|
||
/// The `Content-Type` header. | ||
/// | ||
/// Used to describe the MIME type of message body. Can be used with both | ||
/// requests and responses. | ||
#[derive(Clone, PartialEq, Debug)] | ||
pub struct ContentType(pub Mime); | ||
|
||
impl_header!(ContentType, | ||
"Content-Type", | ||
Mime); | ||
header! { | ||
#[doc="`Content-Type` header, defined in"] | ||
#[doc="[RFC7231](http://tools.ietf.org/html/rfc7231#section-3.1.1.5)"] | ||
#[doc=""] | ||
#[doc="The `Content-Type` header field indicates the media type of the"] | ||
#[doc="associated representation: either the representation enclosed in the"] | ||
#[doc="message payload or the selected representation, as determined by the"] | ||
#[doc="message semantics. The indicated media type defines both the data"] | ||
#[doc="format and how that data is intended to be processed by a recipient,"] | ||
#[doc="within the scope of the received message semantics, after any content"] | ||
#[doc="codings indicated by Content-Encoding are decoded."] | ||
#[doc=""] | ||
#[doc="# ABNF"] | ||
#[doc="```plain"] | ||
#[doc="Content-Type = media-type"] | ||
#[doc="```"] | ||
(ContentType, "Content-Type") => [Mime] | ||
} | ||
|
||
bench_header!(bench, ContentType, { vec![b"application/json; charset=utf-8".to_vec()] }); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.