docs(headers): Update documentation of all remaining headers that use macros
This commit is contained in:
@@ -12,6 +12,11 @@ header! {
|
|||||||
#[doc="```plain"]
|
#[doc="```plain"]
|
||||||
#[doc="Allow = #method"]
|
#[doc="Allow = #method"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
|
#[doc=""]
|
||||||
|
#[doc="# Example values"]
|
||||||
|
#[doc="* `GET, HEAD, PUT`"]
|
||||||
|
#[doc="* `OPTIONS, GET, PUT, POST, DELETE, HEAD, TRACE, CONNECT, PATCH, fOObAr`"]
|
||||||
|
#[doc="* ``"]
|
||||||
(Allow, "Allow") => (Method)*
|
(Allow, "Allow") => (Method)*
|
||||||
|
|
||||||
test_allow {
|
test_allow {
|
||||||
|
|||||||
@@ -16,9 +16,15 @@ header! {
|
|||||||
#[doc="```plain"]
|
#[doc="```plain"]
|
||||||
#[doc="Content-Encoding = 1#content-coding"]
|
#[doc="Content-Encoding = 1#content-coding"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
|
#[doc=""]
|
||||||
|
#[doc="# Example values"]
|
||||||
|
#[doc="* `gzip`"]
|
||||||
(ContentEncoding, "Content-Encoding") => (Encoding)+
|
(ContentEncoding, "Content-Encoding") => (Encoding)+
|
||||||
|
|
||||||
test_content_encoding {}
|
test_content_encoding {
|
||||||
|
/// Testcase from the RFC
|
||||||
|
test_header!(test1, vec![b"gzip"], Some(ContentEncoding(vec![Encoding::Gzip])));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bench_header!(single, ContentEncoding, { vec![b"gzip".to_vec()] });
|
bench_header!(single, ContentEncoding, { vec![b"gzip".to_vec()] });
|
||||||
|
|||||||
@@ -13,6 +13,10 @@ header! {
|
|||||||
#[doc="```plain"]
|
#[doc="```plain"]
|
||||||
#[doc="Content-Language = 1#language-tag"]
|
#[doc="Content-Language = 1#language-tag"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
|
#[doc=""]
|
||||||
|
#[doc="# Example values"]
|
||||||
|
#[doc="* `da`"]
|
||||||
|
#[doc="* `mi, en`"]
|
||||||
(ContentLanguage, "Content-Language") => (QualityItem<Language>)+
|
(ContentLanguage, "Content-Language") => (QualityItem<Language>)+
|
||||||
|
|
||||||
test_content_language {
|
test_content_language {
|
||||||
|
|||||||
@@ -15,6 +15,9 @@ header! {
|
|||||||
#[doc="```plain"]
|
#[doc="```plain"]
|
||||||
#[doc="Content-Length = 1*DIGIT"]
|
#[doc="Content-Length = 1*DIGIT"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
|
#[doc=""]
|
||||||
|
#[doc="# Example values"]
|
||||||
|
#[doc="* `3495`"]
|
||||||
(ContentLength, "Content-Length") => [u64]
|
(ContentLength, "Content-Length") => [u64]
|
||||||
|
|
||||||
test_content_length {
|
test_content_length {
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ header! {
|
|||||||
#[doc="```plain"]
|
#[doc="```plain"]
|
||||||
#[doc="Content-Type = media-type"]
|
#[doc="Content-Type = media-type"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
|
#[doc=""]
|
||||||
|
#[doc="# Example values"]
|
||||||
|
#[doc="* `text/html; charset=ISO-8859-4`"]
|
||||||
(ContentType, "Content-Type") => [Mime]
|
(ContentType, "Content-Type") => [Mime]
|
||||||
|
|
||||||
test_content_type {
|
test_content_type {
|
||||||
|
|||||||
@@ -10,6 +10,9 @@ header! {
|
|||||||
#[doc="```plain"]
|
#[doc="```plain"]
|
||||||
#[doc="Date = HTTP-date"]
|
#[doc="Date = HTTP-date"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
|
#[doc=""]
|
||||||
|
#[doc="# Example values"]
|
||||||
|
#[doc="* `Tue, 15 Nov 1994 08:12:31 GMT`"]
|
||||||
(Date, "Date") => [HttpDate]
|
(Date, "Date") => [HttpDate]
|
||||||
|
|
||||||
test_date {
|
test_date {
|
||||||
|
|||||||
@@ -17,63 +17,30 @@ header! {
|
|||||||
#[doc="```plain"]
|
#[doc="```plain"]
|
||||||
#[doc="ETag = entity-tag"]
|
#[doc="ETag = entity-tag"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
|
#[doc=""]
|
||||||
|
#[doc="# Example values"]
|
||||||
|
#[doc="* `\"xyzzy\"`"]
|
||||||
|
#[doc="* `W/\"xyzzy\"`"]
|
||||||
|
#[doc="* `\"\"`"]
|
||||||
(ETag, "ETag") => [EntityTag]
|
(ETag, "ETag") => [EntityTag]
|
||||||
|
|
||||||
test_etag {
|
test_etag {
|
||||||
test_header!(test1, vec![b"\"xyzzy\""], Some(HeaderField(EntityTag::new(false, "xyzzy".to_string()))));
|
// From the RFC
|
||||||
test_header!(test2, vec![b"W/\"xyzzy\""], Some(HeaderField(EntityTag::new(true, "xyzzy".to_string()))));
|
test_header!(test1, vec![b"\"xyzzy\""], Some(ETag(EntityTag::new(false, "xyzzy".to_string()))));
|
||||||
test_header!(test3, vec![b"\"\""], Some(HeaderField(EntityTag::new(false, "".to_string()))));
|
test_header!(test2, vec![b"W/\"xyzzy\""], Some(ETag(EntityTag::new(true, "xyzzy".to_string()))));
|
||||||
}
|
test_header!(test3, vec![b"\"\""], Some(ETag(EntityTag::new(false, "".to_string()))));
|
||||||
}
|
// Own tests
|
||||||
|
test_header!(test4, vec![b"\"foobar\""], Some(ETag(EntityTag::new(false, "foobar".to_string()))));
|
||||||
#[cfg(test)]
|
test_header!(test5, vec![b"\"\""], Some(ETag(EntityTag::new(false, "".to_string()))));
|
||||||
mod tests {
|
test_header!(test6, vec![b"W/\"weak-etag\""], Some(ETag(EntityTag::new(true, "weak-etag".to_string()))));
|
||||||
use super::ETag;
|
test_header!(test7, vec![b"W/\"\x65\x62\""], Some(ETag(EntityTag::new(true, "\u{0065}\u{0062}".to_string()))));
|
||||||
use header::{Header,EntityTag};
|
test_header!(test8, vec![b"W/\"\""], Some(ETag(EntityTag::new(true, "".to_string()))));
|
||||||
|
test_header!(test9, vec![b"no-dquotes"], None::<ETag>);
|
||||||
#[test]
|
test_header!(test10, vec![b"w/\"the-first-w-is-case-sensitive\""], None::<ETag>);
|
||||||
fn test_etag_successes() {
|
test_header!(test11, vec![b""], None::<ETag>);
|
||||||
// Expected successes
|
test_header!(test12, vec![b"\"unmatched-dquotes1"], None::<ETag>);
|
||||||
let mut etag: Option<ETag>;
|
test_header!(test13, vec![b"unmatched-dquotes2\""], None::<ETag>);
|
||||||
|
test_header!(test14, vec![b"matched-\"dquotes\""], None::<ETag>);
|
||||||
etag = Header::parse_header([b"\"foobar\"".to_vec()].as_ref());
|
|
||||||
assert_eq!(etag, Some(ETag(EntityTag::new(false, "foobar".to_string()))));
|
|
||||||
|
|
||||||
etag = Header::parse_header([b"\"\"".to_vec()].as_ref());
|
|
||||||
assert_eq!(etag, Some(ETag(EntityTag::new(false, "".to_string()))));
|
|
||||||
|
|
||||||
etag = Header::parse_header([b"W/\"weak-etag\"".to_vec()].as_ref());
|
|
||||||
assert_eq!(etag, Some(ETag(EntityTag::new(true, "weak-etag".to_string()))));
|
|
||||||
|
|
||||||
etag = Header::parse_header([b"W/\"\x65\x62\"".to_vec()].as_ref());
|
|
||||||
assert_eq!(etag, Some(ETag(EntityTag::new(true, "\u{0065}\u{0062}".to_string()))));
|
|
||||||
|
|
||||||
etag = Header::parse_header([b"W/\"\"".to_vec()].as_ref());
|
|
||||||
assert_eq!(etag, Some(ETag(EntityTag::new(true, "".to_string()))));
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
|
||||||
fn test_etag_failures() {
|
|
||||||
// Expected failures
|
|
||||||
let mut etag: Option<ETag>;
|
|
||||||
|
|
||||||
etag = Header::parse_header([b"no-dquotes".to_vec()].as_ref());
|
|
||||||
assert_eq!(etag, None);
|
|
||||||
|
|
||||||
etag = Header::parse_header([b"w/\"the-first-w-is-case-sensitive\"".to_vec()].as_ref());
|
|
||||||
assert_eq!(etag, None);
|
|
||||||
|
|
||||||
etag = Header::parse_header([b"".to_vec()].as_ref());
|
|
||||||
assert_eq!(etag, None);
|
|
||||||
|
|
||||||
etag = Header::parse_header([b"\"unmatched-dquotes1".to_vec()].as_ref());
|
|
||||||
assert_eq!(etag, None);
|
|
||||||
|
|
||||||
etag = Header::parse_header([b"unmatched-dquotes2\"".to_vec()].as_ref());
|
|
||||||
assert_eq!(etag, None);
|
|
||||||
|
|
||||||
etag = Header::parse_header([b"matched-\"dquotes\"".to_vec()].as_ref());
|
|
||||||
assert_eq!(etag, None);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,6 +14,9 @@ header! {
|
|||||||
#[doc="```plain"]
|
#[doc="```plain"]
|
||||||
#[doc="Expires = HTTP-date"]
|
#[doc="Expires = HTTP-date"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
|
#[doc=""]
|
||||||
|
#[doc="# Example values"]
|
||||||
|
#[doc="* `Thu, 01 Dec 1994 16:00:00 GMT`"]
|
||||||
(Expires, "Expires") => [HttpDate]
|
(Expires, "Expires") => [HttpDate]
|
||||||
|
|
||||||
test_expires {
|
test_expires {
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ header! {
|
|||||||
#[doc="```plain"]
|
#[doc="```plain"]
|
||||||
#[doc="Expires = HTTP-date"]
|
#[doc="Expires = HTTP-date"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
|
#[doc=""]
|
||||||
|
#[doc="# Example values"]
|
||||||
|
#[doc="* `Sat, 29 Oct 1994 19:43:31 GMT`"]
|
||||||
(LastModified, "Last-Modified") => [HttpDate]
|
(LastModified, "Last-Modified") => [HttpDate]
|
||||||
|
|
||||||
test_last_modified {
|
test_last_modified {
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ header! {
|
|||||||
#[doc="```plain"]
|
#[doc="```plain"]
|
||||||
#[doc="Location = URI-reference"]
|
#[doc="Location = URI-reference"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
|
#[doc=""]
|
||||||
|
#[doc="# Example values"]
|
||||||
|
#[doc="* `/People.html#tim`"]
|
||||||
|
#[doc="* `http://www.example.net/index.html`"]
|
||||||
// TODO: Use URL
|
// TODO: Use URL
|
||||||
(Location, "Location") => [String]
|
(Location, "Location") => [String]
|
||||||
|
|
||||||
|
|||||||
@@ -118,8 +118,10 @@ macro_rules! test_header {
|
|||||||
// Test parsing
|
// Test parsing
|
||||||
assert_eq!(val, $typed);
|
assert_eq!(val, $typed);
|
||||||
// Test formatting
|
// Test formatting
|
||||||
let res: &str = str::from_utf8($raw[0]).unwrap();
|
if $typed != None {
|
||||||
assert_eq!(format!("{}", $typed.unwrap()), res);
|
let res: &str = str::from_utf8($raw[0]).unwrap();
|
||||||
|
assert_eq!(format!("{}", $typed.unwrap()), res);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,9 @@ header! {
|
|||||||
#[doc="```plain"]
|
#[doc="```plain"]
|
||||||
#[doc="Referer = absolute-URI / partial-URI"]
|
#[doc="Referer = absolute-URI / partial-URI"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
|
#[doc=""]
|
||||||
|
#[doc="# Example values"]
|
||||||
|
#[doc="* `http://www.example.org/hypertext/Overview.html`"]
|
||||||
// TODO: Use URL
|
// TODO: Use URL
|
||||||
(Referer, "Referer") => [String]
|
(Referer, "Referer") => [String]
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ header! {
|
|||||||
#[doc="```plain"]
|
#[doc="```plain"]
|
||||||
#[doc="Server = product *( RWS ( product / comment ) )"]
|
#[doc="Server = product *( RWS ( product / comment ) )"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
|
#[doc=""]
|
||||||
|
#[doc="# Example values"]
|
||||||
|
#[doc="* `CERN/3.0 libwww/2.17`"]
|
||||||
// TODO: Maybe parse as defined in the spec?
|
// TODO: Maybe parse as defined in the spec?
|
||||||
(Server, "Server") => [String]
|
(Server, "Server") => [String]
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,9 @@ header! {
|
|||||||
#[doc="```plain"]
|
#[doc="```plain"]
|
||||||
#[doc="Transfer-Encoding = 1#transfer-coding"]
|
#[doc="Transfer-Encoding = 1#transfer-coding"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
|
#[doc=""]
|
||||||
|
#[doc="# Example values"]
|
||||||
|
#[doc="* `gzip, chunked`"]
|
||||||
(TransferEncoding, "Transfer-Encoding") => (Encoding)+
|
(TransferEncoding, "Transfer-Encoding") => (Encoding)+
|
||||||
|
|
||||||
transfer_encoding {
|
transfer_encoding {
|
||||||
|
|||||||
@@ -25,6 +25,9 @@ header! {
|
|||||||
#[doc="protocol-name = token"]
|
#[doc="protocol-name = token"]
|
||||||
#[doc="protocol-version = token"]
|
#[doc="protocol-version = token"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
|
#[doc=""]
|
||||||
|
#[doc="# Example values"]
|
||||||
|
#[doc="* `HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11`"]
|
||||||
(Upgrade, "Upgrade") => (Protocol)+
|
(Upgrade, "Upgrade") => (Protocol)+
|
||||||
|
|
||||||
test_upgrade {
|
test_upgrade {
|
||||||
@@ -41,6 +44,7 @@ header! {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Protocol values that can appear in the Upgrade header.
|
/// Protocol values that can appear in the Upgrade header.
|
||||||
|
// TODO: Parse version part seperately
|
||||||
#[derive(Clone, PartialEq, Debug)]
|
#[derive(Clone, PartialEq, Debug)]
|
||||||
pub enum Protocol {
|
pub enum Protocol {
|
||||||
/// The websocket protocol.
|
/// The websocket protocol.
|
||||||
|
|||||||
@@ -16,19 +16,19 @@ header! {
|
|||||||
#[doc="product = token [\"/\" product-version]"]
|
#[doc="product = token [\"/\" product-version]"]
|
||||||
#[doc="product-version = token"]
|
#[doc="product-version = token"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
// TODO: Maybe write parsing according to the spec? (Split the String)
|
#[doc=""]
|
||||||
|
#[doc="# Example values"]
|
||||||
|
#[doc="* `CERN-LineMode/2.15 libwww/2.17b3`"]
|
||||||
|
#[doc="* `Bunnies`"]
|
||||||
|
#[doc=""]
|
||||||
|
#[doc="# Notes"]
|
||||||
|
#[doc="* The parser does not split the value"]
|
||||||
(UserAgent, "User-Agent") => [String]
|
(UserAgent, "User-Agent") => [String]
|
||||||
|
|
||||||
test_user_agent {
|
test_user_agent {
|
||||||
// Testcase from RFC
|
// Testcase from RFC
|
||||||
test_header!(test1, vec![b"CERN-LineMode/2.15 libwww/2.17b3"]);
|
test_header!(test1, vec![b"CERN-LineMode/2.15 libwww/2.17b3"]);
|
||||||
|
// Own testcase
|
||||||
|
test_header!(test2, vec![b"Bunnies"], Some(UserAgent("Bunnies".to_string())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test] fn test_format() {
|
|
||||||
use std::borrow::ToOwned;
|
|
||||||
use header::Headers;
|
|
||||||
let mut head = Headers::new();
|
|
||||||
head.set(UserAgent("Bunnies".to_owned()));
|
|
||||||
assert!(head.to_string() == "User-Agent: Bunnies\r\n".to_owned());
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -14,28 +14,25 @@ header! {
|
|||||||
#[doc="```plain"]
|
#[doc="```plain"]
|
||||||
#[doc="Vary = \"*\" / 1#field-name"]
|
#[doc="Vary = \"*\" / 1#field-name"]
|
||||||
#[doc="```"]
|
#[doc="```"]
|
||||||
|
#[doc=""]
|
||||||
|
#[doc="# Example values"]
|
||||||
|
#[doc="* `accept-encoding, accept-language`"]
|
||||||
(Vary, "Vary") => {Any / (UniCase<String>)+}
|
(Vary, "Vary") => {Any / (UniCase<String>)+}
|
||||||
|
|
||||||
test_vary {
|
test_vary {
|
||||||
test_header!(test1, vec![b"accept-encoding, accept-language"]);
|
test_header!(test1, vec![b"accept-encoding, accept-language"]);
|
||||||
}
|
|
||||||
}
|
#[test]
|
||||||
|
fn test2() {
|
||||||
#[cfg(test)]
|
let mut vary: Option<Vary>;
|
||||||
mod tests {
|
|
||||||
use super::Vary;
|
vary = Header::parse_header([b"*".to_vec()].as_ref());
|
||||||
use header::Header;
|
assert_eq!(vary, Some(Vary::Any));
|
||||||
|
|
||||||
#[test]
|
vary = Header::parse_header([b"etag,cookie,allow".to_vec()].as_ref());
|
||||||
fn test_vary() {
|
assert_eq!(vary, Some(Vary::Items(vec!["eTag".parse().unwrap(),
|
||||||
let mut vary: Option<Vary>;
|
"cookIE".parse().unwrap(),
|
||||||
|
"AlLOw".parse().unwrap(),])));
|
||||||
vary = Header::parse_header([b"*".to_vec()].as_ref());
|
}
|
||||||
assert_eq!(vary, Some(Vary::Any));
|
|
||||||
|
|
||||||
vary = Header::parse_header([b"etag,cookie,allow".to_vec()].as_ref());
|
|
||||||
assert_eq!(vary, Some(Vary::Items(vec!["eTag".parse().unwrap(),
|
|
||||||
"cookIE".parse().unwrap(),
|
|
||||||
"AlLOw".parse().unwrap(),])));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user