diff --git a/src/header/common/accept.rs b/src/header/common/accept.rs index d8ae5ead..2a5b7560 100644 --- a/src/header/common/accept.rs +++ b/src/header/common/accept.rs @@ -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)), ]))); } } diff --git a/src/header/common/allow.rs b/src/header/common/allow.rs index e9d72f4c..d6e095d9 100644 --- a/src/header/common/allow.rs +++ b/src/header/common/allow.rs @@ -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()] }); diff --git a/src/header/common/authorization.rs b/src/header/common/authorization.rs index b8125c49..c2f1b697 100644 --- a/src/header/common/authorization.rs +++ b/src/header/common/authorization.rs @@ -167,15 +167,19 @@ mod tests { #[test] fn test_raw_auth_parse() { - let header: Authorization = Header::parse_header(&[b"foo bar baz".to_vec()]).unwrap(); + let header: Authorization = 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 = Header::parse_header(&[b"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==".to_vec()]).unwrap(); + let auth: Authorization = 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 = Header::parse_header(&[b"Basic QWxhZGRpbjo=".to_vec()]).unwrap(); + let auth: Authorization = 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, { vec![b"foo bar baz".to_vec()] }); -bench_header!(basic, Authorization, { vec![b"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==".to_vec()] }); +bench_header!(basic, Authorization, { vec![b"Basic QWxhZGRpbjpuIHNlc2FtZQ==".to_vec()] }); diff --git a/src/header/common/cache_control.rs b/src/header/common/cache_control.rs index 20ddadac..df067ce7 100644 --- a/src/header/common/cache_control.rs +++ b/src/header/common/cache_control.rs @@ -168,8 +168,9 @@ 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), - CacheDirective::Extension("bar".to_string(), Some("baz".to_string()))]))) + assert_eq!(cache, Some(CacheControl(vec![ + CacheDirective::Extension("foo".to_string(), None), + CacheDirective::Extension("bar".to_string(), Some("baz".to_string()))]))) } #[test] @@ -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()] }); diff --git a/src/header/common/content_type.rs b/src/header/common/content_type.rs index 6ffdd299..d8827359 100644 --- a/src/header/common/content_type.rs +++ b/src/header/common/content_type.rs @@ -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()))])))); } } diff --git a/src/header/common/cookie.rs b/src/header/common/cookie.rs index c37db48c..f9952793 100644 --- a/src/header/common/cookie.rs +++ b/src/header/common/cookie.rs @@ -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); diff --git a/src/header/common/etag.rs b/src/header/common/etag.rs index 04346c2f..14af9a2b 100644 --- a/src/header/common/etag.rs +++ b/src/header/common/etag.rs @@ -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::); - test_header!(test10, vec![b"w/\"the-first-w-is-case-sensitive\""], None::); - test_header!(test11, vec![b""], None::); - test_header!(test12, vec![b"\"unmatched-dquotes1"], None::); - test_header!(test13, vec![b"unmatched-dquotes2\""], None::); - test_header!(test14, vec![b"matched-\"dquotes\""], None::); + 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::); + test_header!(test10, + vec![b"w/\"the-first-w-is-case-sensitive\""], + None::); + test_header!(test11, + vec![b""], + None::); + test_header!(test12, + vec![b"\"unmatched-dquotes1"], + None::); + test_header!(test13, + vec![b"unmatched-dquotes2\""], + None::); + test_header!(test14, + vec![b"matched-\"dquotes\""], + None::); } } diff --git a/src/header/common/last_modified.rs b/src/header/common/last_modified.rs index 026363c0..ab9830e3 100644 --- a/src/header/common/last_modified.rs +++ b/src/header/common/last_modified.rs @@ -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"] diff --git a/src/header/common/mod.rs b/src/header/common/mod.rs index 7e2d771a..762edaf0 100644 --- a/src/header/common/mod.rs +++ b/src/header/common/mod.rs @@ -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 = result.to_ascii_lowercase().split(' ').map(|x| x.to_string()).collect(); - let expected_cmp: Vec = expected.to_ascii_lowercase().split(' ').map(|x| x.to_string()).collect(); + let result_cmp: Vec = result + .to_ascii_lowercase() + .split(' ') + .map(|x| x.to_string()) + .collect(); + let expected_cmp: Vec = 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[..]) } } } diff --git a/src/header/common/set_cookie.rs b/src/header/common/set_cookie.rs index fc958541..604f1b2a 100644 --- a/src/header/common/set_cookie.rs +++ b/src/header/common/set_cookie.rs @@ -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] diff --git a/src/header/mod.rs b/src/header/mod.rs index f14fda29..56be8892 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -94,8 +94,7 @@ impl Clone for Box { #[inline] fn header_name() -> &'static str { - let name = ::header_name(); - name + ::header_name() } /// A map of header fields on requests and responses.