style(headers): Break lines with over 100 characters
This commit is contained in:
@@ -48,7 +48,9 @@ header! {
|
||||
Some(HeaderField(vec![
|
||||
QualityItem::new(Mime(TopLevel::Text, SubLevel::Plain, vec![]), Quality(500)),
|
||||
qitem(Mime(TopLevel::Text, SubLevel::Html, vec![])),
|
||||
QualityItem::new(Mime(TopLevel::Text, SubLevel::Ext("x-dvi".to_string()), vec![]), Quality(800)),
|
||||
QualityItem::new(
|
||||
Mime(TopLevel::Text, SubLevel::Ext("x-dvi".to_string()), vec![]),
|
||||
Quality(800)),
|
||||
qitem(Mime(TopLevel::Text, SubLevel::Ext("x-c".to_string()), vec![])),
|
||||
])));
|
||||
// Custom tests
|
||||
@@ -62,7 +64,9 @@ header! {
|
||||
test4,
|
||||
vec![b"text/plain; charset=utf-8; q=0.5"],
|
||||
Some(Accept(vec![
|
||||
QualityItem::new(Mime(TopLevel::Text, SubLevel::Plain, vec![(Attr::Charset, Value::Utf8)]), Quality(500)),
|
||||
QualityItem::new(Mime(TopLevel::Text,
|
||||
SubLevel::Plain, vec![(Attr::Charset, Value::Utf8)]),
|
||||
Quality(500)),
|
||||
])));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -47,4 +47,5 @@ header! {
|
||||
}
|
||||
}
|
||||
|
||||
bench_header!(bench, Allow, { vec![b"OPTIONS,GET,PUT,POST,DELETE,HEAD,TRACE,CONNECT,PATCH,fOObAr".to_vec()] });
|
||||
bench_header!(bench,
|
||||
Allow, { vec![b"OPTIONS,GET,PUT,POST,DELETE,HEAD,TRACE,CONNECT,PATCH,fOObAr".to_vec()] });
|
||||
|
||||
@@ -167,15 +167,19 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_raw_auth_parse() {
|
||||
let header: Authorization<String> = Header::parse_header(&[b"foo bar baz".to_vec()]).unwrap();
|
||||
let header: Authorization<String> = Header::parse_header(
|
||||
&[b"foo bar baz".to_vec()]).unwrap();
|
||||
assert_eq!(header.0, "foo bar baz");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_basic_auth() {
|
||||
let mut headers = Headers::new();
|
||||
headers.set(Authorization(Basic { username: "Aladdin".to_string(), password: Some("open sesame".to_string()) }));
|
||||
assert_eq!(headers.to_string(), "Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n".to_string());
|
||||
headers.set(Authorization(
|
||||
Basic { username: "Aladdin".to_string(), password: Some("open sesame".to_string()) }));
|
||||
assert_eq!(
|
||||
headers.to_string(),
|
||||
"Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n".to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -187,14 +191,16 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_basic_auth_parse() {
|
||||
let auth: Authorization<Basic> = Header::parse_header(&[b"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==".to_vec()]).unwrap();
|
||||
let auth: Authorization<Basic> = Header::parse_header(
|
||||
&[b"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==".to_vec()]).unwrap();
|
||||
assert_eq!(auth.0.username, "Aladdin");
|
||||
assert_eq!(auth.0.password, Some("open sesame".to_string()));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_basic_auth_parse_no_password() {
|
||||
let auth: Authorization<Basic> = Header::parse_header(&[b"Basic QWxhZGRpbjo=".to_vec()]).unwrap();
|
||||
let auth: Authorization<Basic> = Header::parse_header(
|
||||
&[b"Basic QWxhZGRpbjo=".to_vec()]).unwrap();
|
||||
assert_eq!(auth.0.username, "Aladdin");
|
||||
assert_eq!(auth.0.password, Some("".to_string()));
|
||||
}
|
||||
@@ -202,4 +208,4 @@ mod tests {
|
||||
}
|
||||
|
||||
bench_header!(raw, Authorization<String>, { vec![b"foo bar baz".to_vec()] });
|
||||
bench_header!(basic, Authorization<Basic>, { vec![b"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==".to_vec()] });
|
||||
bench_header!(basic, Authorization<Basic>, { vec![b"Basic QWxhZGRpbjpuIHNlc2FtZQ==".to_vec()] });
|
||||
|
||||
@@ -168,7 +168,8 @@ mod tests {
|
||||
#[test]
|
||||
fn test_parse_extension() {
|
||||
let cache = Header::parse_header(&[b"foo, bar=baz".to_vec()]);
|
||||
assert_eq!(cache, Some(CacheControl(vec![CacheDirective::Extension("foo".to_string(), None),
|
||||
assert_eq!(cache, Some(CacheControl(vec![
|
||||
CacheDirective::Extension("foo".to_string(), None),
|
||||
CacheDirective::Extension("bar".to_string(), Some("baz".to_string()))])))
|
||||
}
|
||||
|
||||
@@ -179,4 +180,5 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
bench_header!(normal, CacheControl, { vec![b"no-cache, private".to_vec(), b"max-age=100".to_vec()] });
|
||||
bench_header!(normal,
|
||||
CacheControl, { vec![b"no-cache, private".to_vec(), b"max-age=100".to_vec()] });
|
||||
|
||||
@@ -27,7 +27,10 @@ header! {
|
||||
// FIXME: Should be b"text/html; charset=ISO-8859-4" but mime crate lowercases
|
||||
// the whole value so parsing and formatting the value gives a different result
|
||||
vec![b"text/html; charset=iso-8859-4"],
|
||||
Some(HeaderField(Mime(TopLevel::Text, SubLevel::Html, vec![(Attr::Charset, Value::Ext("iso-8859-4".to_string()))]))));
|
||||
Some(HeaderField(Mime(
|
||||
TopLevel::Text,
|
||||
SubLevel::Html,
|
||||
vec![(Attr::Charset, Value::Ext("iso-8859-4".to_string()))]))));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -98,7 +98,9 @@ fn test_fmt() {
|
||||
let mut cookie_pair = CookiePair::new("foo".to_string(), "bar".to_string());
|
||||
cookie_pair.httponly = true;
|
||||
cookie_pair.path = Some("/p".to_string());
|
||||
let cookie_header = Cookie(vec![cookie_pair, CookiePair::new("baz".to_string(), "quux".to_string())]);
|
||||
let cookie_header = Cookie(vec![
|
||||
cookie_pair,
|
||||
CookiePair::new("baz".to_string(),"quux".to_string())]);
|
||||
let mut headers = Headers::new();
|
||||
headers.set(cookie_header);
|
||||
|
||||
|
||||
@@ -26,21 +26,49 @@ header! {
|
||||
|
||||
test_etag {
|
||||
// From the RFC
|
||||
test_header!(test1, vec![b"\"xyzzy\""], Some(ETag(EntityTag::new(false, "xyzzy".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()))));
|
||||
test_header!(test1,
|
||||
vec![b"\"xyzzy\""],
|
||||
Some(ETag(EntityTag::new(false, "xyzzy".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()))));
|
||||
test_header!(test5, vec![b"\"\""], Some(ETag(EntityTag::new(false, "".to_string()))));
|
||||
test_header!(test6, vec![b"W/\"weak-etag\""], Some(ETag(EntityTag::new(true, "weak-etag".to_string()))));
|
||||
test_header!(test7, vec![b"W/\"\x65\x62\""], Some(ETag(EntityTag::new(true, "\u{0065}\u{0062}".to_string()))));
|
||||
test_header!(test8, vec![b"W/\"\""], Some(ETag(EntityTag::new(true, "".to_string()))));
|
||||
test_header!(test9, vec![b"no-dquotes"], None::<ETag>);
|
||||
test_header!(test10, vec![b"w/\"the-first-w-is-case-sensitive\""], None::<ETag>);
|
||||
test_header!(test11, vec![b""], None::<ETag>);
|
||||
test_header!(test12, vec![b"\"unmatched-dquotes1"], None::<ETag>);
|
||||
test_header!(test13, vec![b"unmatched-dquotes2\""], None::<ETag>);
|
||||
test_header!(test14, vec![b"matched-\"dquotes\""], None::<ETag>);
|
||||
test_header!(test4,
|
||||
vec![b"\"foobar\""],
|
||||
Some(ETag(EntityTag::new(false, "foobar".to_string()))));
|
||||
test_header!(test5,
|
||||
vec![b"\"\""],
|
||||
Some(ETag(EntityTag::new(false, "".to_string()))));
|
||||
test_header!(test6,
|
||||
vec![b"W/\"weak-etag\""],
|
||||
Some(ETag(EntityTag::new(true, "weak-etag".to_string()))));
|
||||
test_header!(test7,
|
||||
vec![b"W/\"\x65\x62\""],
|
||||
Some(ETag(EntityTag::new(true, "\u{0065}\u{0062}".to_string()))));
|
||||
test_header!(test8,
|
||||
vec![b"W/\"\""],
|
||||
Some(ETag(EntityTag::new(true, "".to_string()))));
|
||||
test_header!(test9,
|
||||
vec![b"no-dquotes"],
|
||||
None::<ETag>);
|
||||
test_header!(test10,
|
||||
vec![b"w/\"the-first-w-is-case-sensitive\""],
|
||||
None::<ETag>);
|
||||
test_header!(test11,
|
||||
vec![b""],
|
||||
None::<ETag>);
|
||||
test_header!(test12,
|
||||
vec![b"\"unmatched-dquotes1"],
|
||||
None::<ETag>);
|
||||
test_header!(test13,
|
||||
vec![b"unmatched-dquotes2\""],
|
||||
None::<ETag>);
|
||||
test_header!(test14,
|
||||
vec![b"matched-\"dquotes\""],
|
||||
None::<ETag>);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
use header::HttpDate;
|
||||
|
||||
header! {
|
||||
#[doc="`Last-Modified` header, defined in [RFC7232](http://tools.ietf.org/html/rfc7232#section-2.2)"]
|
||||
#[doc="`Last-Modified` header, defined in"]
|
||||
#[doc="[RFC7232](http://tools.ietf.org/html/rfc7232#section-2.2)"]
|
||||
#[doc=""]
|
||||
#[doc="The `Last-Modified` header field in a response provides a timestamp"]
|
||||
#[doc="indicating the date and time at which the origin server believes the"]
|
||||
|
||||
@@ -124,8 +124,16 @@ macro_rules! test_header {
|
||||
let value = HeaderField::parse_header(&a[..]);
|
||||
let result = format!("{}", value.unwrap());
|
||||
let expected = String::from_utf8(raw[0].to_vec()).unwrap();
|
||||
let result_cmp: Vec<String> = result.to_ascii_lowercase().split(' ').map(|x| x.to_string()).collect();
|
||||
let expected_cmp: Vec<String> = expected.to_ascii_lowercase().split(' ').map(|x| x.to_string()).collect();
|
||||
let result_cmp: Vec<String> = result
|
||||
.to_ascii_lowercase()
|
||||
.split(' ')
|
||||
.map(|x| x.to_string())
|
||||
.collect();
|
||||
let expected_cmp: Vec<String> = expected
|
||||
.to_ascii_lowercase()
|
||||
.split(' ')
|
||||
.map(|x| x.to_string())
|
||||
.collect();
|
||||
assert_eq!(result_cmp.concat(), expected_cmp.concat());
|
||||
}
|
||||
};
|
||||
@@ -259,7 +267,8 @@ macro_rules! header {
|
||||
fn fmt_header(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
|
||||
match *self {
|
||||
$id::Any => f.write_str("*"),
|
||||
$id::Items(ref fields) => $crate::header::parsing::fmt_comma_delimited(f, &fields[..])
|
||||
$id::Items(ref fields) => $crate::header::parsing::fmt_comma_delimited(
|
||||
f, &fields[..])
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -134,7 +134,9 @@ fn test_fmt() {
|
||||
let mut headers = Headers::new();
|
||||
headers.set(cookies);
|
||||
|
||||
assert_eq!(&headers.to_string()[..], "Set-Cookie: foo=bar; HttpOnly; Path=/p\r\nSet-Cookie: baz=quux; Path=/\r\n");
|
||||
assert_eq!(
|
||||
&headers.to_string()[..],
|
||||
"Set-Cookie: foo=bar; HttpOnly; Path=/p\r\nSet-Cookie: baz=quux; Path=/\r\n");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -94,8 +94,7 @@ impl Clone for Box<HeaderFormat + Send + Sync> {
|
||||
|
||||
#[inline]
|
||||
fn header_name<T: Header>() -> &'static str {
|
||||
let name = <T as Header>::header_name();
|
||||
name
|
||||
<T as Header>::header_name()
|
||||
}
|
||||
|
||||
/// A map of header fields on requests and responses.
|
||||
|
||||
Reference in New Issue
Block a user