style(headers): Break lines with over 100 characters

This commit is contained in:
Pyfisch
2015-05-03 15:45:11 +02:00
parent 66d54d03e7
commit db4d89189a
11 changed files with 92 additions and 35 deletions

View File

@@ -48,7 +48,9 @@ header! {
Some(HeaderField(vec![ Some(HeaderField(vec![
QualityItem::new(Mime(TopLevel::Text, SubLevel::Plain, vec![]), Quality(500)), QualityItem::new(Mime(TopLevel::Text, SubLevel::Plain, vec![]), Quality(500)),
qitem(Mime(TopLevel::Text, SubLevel::Html, vec![])), 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![])), qitem(Mime(TopLevel::Text, SubLevel::Ext("x-c".to_string()), vec![])),
]))); ])));
// Custom tests // Custom tests
@@ -62,7 +64,9 @@ header! {
test4, test4,
vec![b"text/plain; charset=utf-8; q=0.5"], vec![b"text/plain; charset=utf-8; q=0.5"],
Some(Accept(vec![ 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)),
]))); ])));
} }
} }

View File

@@ -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()] });

View File

@@ -167,15 +167,19 @@ mod tests {
#[test] #[test]
fn test_raw_auth_parse() { 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"); assert_eq!(header.0, "foo bar baz");
} }
#[test] #[test]
fn test_basic_auth() { fn test_basic_auth() {
let mut headers = Headers::new(); let mut headers = Headers::new();
headers.set(Authorization(Basic { username: "Aladdin".to_string(), password: Some("open sesame".to_string()) })); headers.set(Authorization(
assert_eq!(headers.to_string(), "Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n".to_string()); Basic { username: "Aladdin".to_string(), password: Some("open sesame".to_string()) }));
assert_eq!(
headers.to_string(),
"Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n".to_string());
} }
#[test] #[test]
@@ -187,14 +191,16 @@ mod tests {
#[test] #[test]
fn test_basic_auth_parse() { 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.username, "Aladdin");
assert_eq!(auth.0.password, Some("open sesame".to_string())); assert_eq!(auth.0.password, Some("open sesame".to_string()));
} }
#[test] #[test]
fn test_basic_auth_parse_no_password() { 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.username, "Aladdin");
assert_eq!(auth.0.password, Some("".to_string())); 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!(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()] });

View File

@@ -168,8 +168,9 @@ mod tests {
#[test] #[test]
fn test_parse_extension() { fn test_parse_extension() {
let cache = Header::parse_header(&[b"foo, bar=baz".to_vec()]); 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("bar".to_string(), Some("baz".to_string()))]))) CacheDirective::Extension("foo".to_string(), None),
CacheDirective::Extension("bar".to_string(), Some("baz".to_string()))])))
} }
#[test] #[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()] });

View File

@@ -27,7 +27,10 @@ header! {
// FIXME: Should be b"text/html; charset=ISO-8859-4" but mime crate lowercases // 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 // the whole value so parsing and formatting the value gives a different result
vec![b"text/html; charset=iso-8859-4"], 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()))]))));
} }
} }

View File

@@ -98,7 +98,9 @@ fn test_fmt() {
let mut cookie_pair = CookiePair::new("foo".to_string(), "bar".to_string()); let mut cookie_pair = CookiePair::new("foo".to_string(), "bar".to_string());
cookie_pair.httponly = true; cookie_pair.httponly = true;
cookie_pair.path = Some("/p".to_string()); 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(); let mut headers = Headers::new();
headers.set(cookie_header); headers.set(cookie_header);

View File

@@ -26,21 +26,49 @@ header! {
test_etag { test_etag {
// From the RFC // From the RFC
test_header!(test1, vec![b"\"xyzzy\""], Some(ETag(EntityTag::new(false, "xyzzy".to_string())))); test_header!(test1,
test_header!(test2, vec![b"W/\"xyzzy\""], Some(ETag(EntityTag::new(true, "xyzzy".to_string())))); vec![b"\"xyzzy\""],
test_header!(test3, vec![b"\"\""], Some(ETag(EntityTag::new(false, "".to_string())))); 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 // Own tests
test_header!(test4, vec![b"\"foobar\""], Some(ETag(EntityTag::new(false, "foobar".to_string())))); test_header!(test4,
test_header!(test5, vec![b"\"\""], Some(ETag(EntityTag::new(false, "".to_string())))); vec![b"\"foobar\""],
test_header!(test6, vec![b"W/\"weak-etag\""], Some(ETag(EntityTag::new(true, "weak-etag".to_string())))); Some(ETag(EntityTag::new(false, "foobar".to_string()))));
test_header!(test7, vec![b"W/\"\x65\x62\""], Some(ETag(EntityTag::new(true, "\u{0065}\u{0062}".to_string())))); test_header!(test5,
test_header!(test8, vec![b"W/\"\""], Some(ETag(EntityTag::new(true, "".to_string())))); vec![b"\"\""],
test_header!(test9, vec![b"no-dquotes"], None::<ETag>); Some(ETag(EntityTag::new(false, "".to_string()))));
test_header!(test10, vec![b"w/\"the-first-w-is-case-sensitive\""], None::<ETag>); test_header!(test6,
test_header!(test11, vec![b""], None::<ETag>); vec![b"W/\"weak-etag\""],
test_header!(test12, vec![b"\"unmatched-dquotes1"], None::<ETag>); Some(ETag(EntityTag::new(true, "weak-etag".to_string()))));
test_header!(test13, vec![b"unmatched-dquotes2\""], None::<ETag>); test_header!(test7,
test_header!(test14, vec![b"matched-\"dquotes\""], None::<ETag>); 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>);
} }
} }

View File

@@ -1,7 +1,8 @@
use header::HttpDate; use header::HttpDate;
header! { 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=""]
#[doc="The `Last-Modified` header field in a response provides a timestamp"] #[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"] #[doc="indicating the date and time at which the origin server believes the"]

View File

@@ -124,8 +124,16 @@ macro_rules! test_header {
let value = HeaderField::parse_header(&a[..]); let value = HeaderField::parse_header(&a[..]);
let result = format!("{}", value.unwrap()); let result = format!("{}", value.unwrap());
let expected = String::from_utf8(raw[0].to_vec()).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 result_cmp: Vec<String> = result
let expected_cmp: Vec<String> = expected.to_ascii_lowercase().split(' ').map(|x| x.to_string()).collect(); .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()); 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 { fn fmt_header(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result {
match *self { match *self {
$id::Any => f.write_str("*"), $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[..])
} }
} }
} }

View File

@@ -134,7 +134,9 @@ fn test_fmt() {
let mut headers = Headers::new(); let mut headers = Headers::new();
headers.set(cookies); 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] #[test]

View File

@@ -94,8 +94,7 @@ impl Clone for Box<HeaderFormat + Send + Sync> {
#[inline] #[inline]
fn header_name<T: Header>() -> &'static str { fn header_name<T: Header>() -> &'static str {
let name = <T as Header>::header_name(); <T as Header>::header_name()
name
} }
/// A map of header fields on requests and responses. /// A map of header fields on requests and responses.