perf(all): replace &str.to_string() with .to_owned()
This commit is contained in:
@@ -430,7 +430,7 @@ mod tests {
|
|||||||
client.set_redirect_policy(RedirectPolicy::FollowAll);
|
client.set_redirect_policy(RedirectPolicy::FollowAll);
|
||||||
|
|
||||||
let res = client.get("http://127.0.0.1").send().unwrap();
|
let res = client.get("http://127.0.0.1").send().unwrap();
|
||||||
assert_eq!(res.headers.get(), Some(&Server("mock3".to_string())));
|
assert_eq!(res.headers.get(), Some(&Server("mock3".to_owned())));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -438,7 +438,7 @@ mod tests {
|
|||||||
let mut client = Client::with_connector(MockRedirectPolicy);
|
let mut client = Client::with_connector(MockRedirectPolicy);
|
||||||
client.set_redirect_policy(RedirectPolicy::FollowNone);
|
client.set_redirect_policy(RedirectPolicy::FollowNone);
|
||||||
let res = client.get("http://127.0.0.1").send().unwrap();
|
let res = client.get("http://127.0.0.1").send().unwrap();
|
||||||
assert_eq!(res.headers.get(), Some(&Server("mock1".to_string())));
|
assert_eq!(res.headers.get(), Some(&Server("mock1".to_owned())));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -449,7 +449,7 @@ mod tests {
|
|||||||
let mut client = Client::with_connector(MockRedirectPolicy);
|
let mut client = Client::with_connector(MockRedirectPolicy);
|
||||||
client.set_redirect_policy(RedirectPolicy::FollowIf(follow_if));
|
client.set_redirect_policy(RedirectPolicy::FollowIf(follow_if));
|
||||||
let res = client.get("http://127.0.0.1").send().unwrap();
|
let res = client.get("http://127.0.0.1").send().unwrap();
|
||||||
assert_eq!(res.headers.get(), Some(&Server("mock2".to_string())));
|
assert_eq!(res.headers.get(), Some(&Server("mock2".to_owned())));
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tests that the `Client::set_ssl_verifier` method does not drop the
|
/// Tests that the `Client::set_ssl_verifier` method does not drop the
|
||||||
|
|||||||
@@ -172,7 +172,7 @@ mod tests {
|
|||||||
None => panic!("Transfer-Encoding: chunked expected!"),
|
None => panic!("Transfer-Encoding: chunked expected!"),
|
||||||
};
|
};
|
||||||
// The body is correct?
|
// The body is correct?
|
||||||
assert_eq!(read_to_string(res).unwrap(), "qwert".to_string());
|
assert_eq!(read_to_string(res).unwrap(), "qwert".to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tests that when a chunk size is not a valid radix-16 number, an error
|
/// Tests that when a chunk size is not a valid radix-16 number, an error
|
||||||
@@ -229,6 +229,6 @@ mod tests {
|
|||||||
|
|
||||||
let res = Response::new(Box::new(stream)).unwrap();
|
let res = Response::new(Box::new(stream)).unwrap();
|
||||||
|
|
||||||
assert_eq!(read_to_string(res).unwrap(), "1".to_string());
|
assert_eq!(read_to_string(res).unwrap(), "1".to_owned());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ header! {
|
|||||||
// vec![b"audio/*; q=0.2, audio/basic"],
|
// vec![b"audio/*; q=0.2, audio/basic"],
|
||||||
// Some(HeaderField(vec![
|
// Some(HeaderField(vec![
|
||||||
// QualityItem::new(Mime(TopLevel::Audio, SubLevel::Star, vec![]), Quality(200)),
|
// QualityItem::new(Mime(TopLevel::Audio, SubLevel::Star, vec![]), Quality(200)),
|
||||||
// qitem(Mime(TopLevel::Audio, SubLevel::Ext("basic".to_string()), vec![])),
|
// qitem(Mime(TopLevel::Audio, SubLevel::Ext("basic".to_owned()), vec![])),
|
||||||
// ])));
|
// ])));
|
||||||
test_header!(
|
test_header!(
|
||||||
test2,
|
test2,
|
||||||
@@ -49,9 +49,9 @@ header! {
|
|||||||
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(
|
QualityItem::new(
|
||||||
Mime(TopLevel::Text, SubLevel::Ext("x-dvi".to_string()), vec![]),
|
Mime(TopLevel::Text, SubLevel::Ext("x-dvi".to_owned()), vec![]),
|
||||||
Quality(800)),
|
Quality(800)),
|
||||||
qitem(Mime(TopLevel::Text, SubLevel::Ext("x-c".to_string()), vec![])),
|
qitem(Mime(TopLevel::Text, SubLevel::Ext("x-c".to_owned()), vec![])),
|
||||||
])));
|
])));
|
||||||
// Custom tests
|
// Custom tests
|
||||||
test_header!(
|
test_header!(
|
||||||
|
|||||||
@@ -26,9 +26,9 @@ header! {
|
|||||||
test_header!(
|
test_header!(
|
||||||
test2, vec![b"en-us, en; q=0.5, fr"],
|
test2, vec![b"en-us, en; q=0.5, fr"],
|
||||||
Some(AcceptLanguage(vec![
|
Some(AcceptLanguage(vec![
|
||||||
qitem(Language {primary: "en".to_string(), sub: Some("us".to_string())}),
|
qitem(Language {primary: "en".to_owned(), sub: Some("us".to_owned())}),
|
||||||
QualityItem::new(Language{primary: "en".to_string(), sub: None}, Quality(500)),
|
QualityItem::new(Language{primary: "en".to_owned(), sub: None}, Quality(500)),
|
||||||
qitem(Language {primary: "fr".to_string(), sub: None}),
|
qitem(Language {primary: "fr".to_owned(), sub: None}),
|
||||||
])));
|
])));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -58,7 +58,7 @@ impl FromStr for RangeUnit {
|
|||||||
"bytes" => Ok(RangeUnit::Bytes),
|
"bytes" => Ok(RangeUnit::Bytes),
|
||||||
"none" => Ok(RangeUnit::None),
|
"none" => Ok(RangeUnit::None),
|
||||||
// FIXME: Check if s is really a Token
|
// FIXME: Check if s is really a Token
|
||||||
_ => Ok(RangeUnit::Unregistered(s.to_string())),
|
_ => Ok(RangeUnit::Unregistered(s.to_owned())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ header! {
|
|||||||
Method::Trace,
|
Method::Trace,
|
||||||
Method::Connect,
|
Method::Connect,
|
||||||
Method::Patch,
|
Method::Patch,
|
||||||
Method::Extension("fOObAr".to_string())])));
|
Method::Extension("fOObAr".to_owned())])));
|
||||||
test_header!(
|
test_header!(
|
||||||
test3,
|
test3,
|
||||||
vec![b""],
|
vec![b""],
|
||||||
|
|||||||
@@ -128,11 +128,11 @@ impl FromStr for Basic {
|
|||||||
Ok(text) => {
|
Ok(text) => {
|
||||||
let mut parts = &mut text.split(':');
|
let mut parts = &mut text.split(':');
|
||||||
let user = match parts.next() {
|
let user = match parts.next() {
|
||||||
Some(part) => part.to_string(),
|
Some(part) => part.to_owned(),
|
||||||
None => return Err(())
|
None => return Err(())
|
||||||
};
|
};
|
||||||
let password = match parts.next() {
|
let password = match parts.next() {
|
||||||
Some(part) => Some(part.to_string()),
|
Some(part) => Some(part.to_owned()),
|
||||||
None => None
|
None => None
|
||||||
};
|
};
|
||||||
Ok(Basic {
|
Ok(Basic {
|
||||||
@@ -161,8 +161,8 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_raw_auth() {
|
fn test_raw_auth() {
|
||||||
let mut headers = Headers::new();
|
let mut headers = Headers::new();
|
||||||
headers.set(Authorization("foo bar baz".to_string()));
|
headers.set(Authorization("foo bar baz".to_owned()));
|
||||||
assert_eq!(headers.to_string(), "Authorization: foo bar baz\r\n".to_string());
|
assert_eq!(headers.to_string(), "Authorization: foo bar baz\r\n".to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -176,17 +176,17 @@ mod tests {
|
|||||||
fn test_basic_auth() {
|
fn test_basic_auth() {
|
||||||
let mut headers = Headers::new();
|
let mut headers = Headers::new();
|
||||||
headers.set(Authorization(
|
headers.set(Authorization(
|
||||||
Basic { username: "Aladdin".to_string(), password: Some("open sesame".to_string()) }));
|
Basic { username: "Aladdin".to_owned(), password: Some("open sesame".to_owned()) }));
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
headers.to_string(),
|
headers.to_string(),
|
||||||
"Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n".to_string());
|
"Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\r\n".to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_basic_auth_no_password() {
|
fn test_basic_auth_no_password() {
|
||||||
let mut headers = Headers::new();
|
let mut headers = Headers::new();
|
||||||
headers.set(Authorization(Basic { username: "Aladdin".to_string(), password: None }));
|
headers.set(Authorization(Basic { username: "Aladdin".to_owned(), password: None }));
|
||||||
assert_eq!(headers.to_string(), "Authorization: Basic QWxhZGRpbjo=\r\n".to_string());
|
assert_eq!(headers.to_string(), "Authorization: Basic QWxhZGRpbjo=\r\n".to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -194,7 +194,7 @@ mod tests {
|
|||||||
let auth: Authorization<Basic> = Header::parse_header(
|
let auth: Authorization<Basic> = Header::parse_header(
|
||||||
&[b"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==".to_vec()]).unwrap();
|
&[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_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -202,7 +202,7 @@ mod tests {
|
|||||||
let auth: Authorization<Basic> = Header::parse_header(
|
let auth: Authorization<Basic> = Header::parse_header(
|
||||||
&[b"Basic QWxhZGRpbjo=".to_vec()]).unwrap();
|
&[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_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -126,15 +126,15 @@ impl FromStr for CacheDirective {
|
|||||||
"proxy-revalidate" => Ok(ProxyRevalidate),
|
"proxy-revalidate" => Ok(ProxyRevalidate),
|
||||||
"" => Err(None),
|
"" => Err(None),
|
||||||
_ => match s.find('=') {
|
_ => match s.find('=') {
|
||||||
Some(idx) if idx+1 < s.len() => match (&s[..idx], &s[idx+1..].trim_matches('"')) {
|
Some(idx) if idx+1 < s.len() => match (&s[..idx], (&s[idx+1..]).trim_matches('"')) {
|
||||||
("max-age" , secs) => secs.parse().map(MaxAge).map_err(|x| Some(x)),
|
("max-age" , secs) => secs.parse().map(MaxAge).map_err(|x| Some(x)),
|
||||||
("max-stale", secs) => secs.parse().map(MaxStale).map_err(|x| Some(x)),
|
("max-stale", secs) => secs.parse().map(MaxStale).map_err(|x| Some(x)),
|
||||||
("min-fresh", secs) => secs.parse().map(MinFresh).map_err(|x| Some(x)),
|
("min-fresh", secs) => secs.parse().map(MinFresh).map_err(|x| Some(x)),
|
||||||
("s-maxage", secs) => secs.parse().map(SMaxAge).map_err(|x| Some(x)),
|
("s-maxage", secs) => secs.parse().map(SMaxAge).map_err(|x| Some(x)),
|
||||||
(left, right) => Ok(Extension(left.to_string(), Some(right.to_string())))
|
(left, right) => Ok(Extension(left.to_owned(), Some(right.to_owned())))
|
||||||
},
|
},
|
||||||
Some(_) => Err(None),
|
Some(_) => Err(None),
|
||||||
None => Ok(Extension(s.to_string(), None))
|
None => Ok(Extension(s.to_owned(), None))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -169,8 +169,8 @@ mod tests {
|
|||||||
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![
|
assert_eq!(cache, Some(CacheControl(vec![
|
||||||
CacheDirective::Extension("foo".to_string(), None),
|
CacheDirective::Extension("foo".to_owned(), None),
|
||||||
CacheDirective::Extension("bar".to_string(), Some("baz".to_string()))])))
|
CacheDirective::Extension("bar".to_owned(), Some("baz".to_owned()))])))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ impl FromStr for ConnectionOption {
|
|||||||
match s {
|
match s {
|
||||||
"keep-alive" => Ok(KeepAlive),
|
"keep-alive" => Ok(KeepAlive),
|
||||||
"close" => Ok(Close),
|
"close" => Ok(Close),
|
||||||
s => Ok(ConnectionHeader(UniCase(s.to_string())))
|
s => Ok(ConnectionHeader(UniCase(s.to_owned())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ header! {
|
|||||||
Some(HeaderField(Mime(
|
Some(HeaderField(Mime(
|
||||||
TopLevel::Text,
|
TopLevel::Text,
|
||||||
SubLevel::Html,
|
SubLevel::Html,
|
||||||
vec![(Attr::Charset, Value::Ext("iso-8859-4".to_string()))]))));
|
vec![(Attr::Charset, Value::Ext("iso-8859-4".to_owned()))]))));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -86,8 +86,8 @@ impl Cookie {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_parse() {
|
fn test_parse() {
|
||||||
let h = Header::parse_header(&[b"foo=bar; baz=quux".to_vec()][..]);
|
let h = Header::parse_header(&[b"foo=bar; baz=quux".to_vec()][..]);
|
||||||
let c1 = CookiePair::new("foo".to_string(), "bar".to_string());
|
let c1 = CookiePair::new("foo".to_owned(), "bar".to_owned());
|
||||||
let c2 = CookiePair::new("baz".to_string(), "quux".to_string());
|
let c2 = CookiePair::new("baz".to_owned(), "quux".to_owned());
|
||||||
assert_eq!(h, Some(Cookie(vec![c1, c2])));
|
assert_eq!(h, Some(Cookie(vec![c1, c2])));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,12 +95,12 @@ fn test_parse() {
|
|||||||
fn test_fmt() {
|
fn test_fmt() {
|
||||||
use header::Headers;
|
use header::Headers;
|
||||||
|
|
||||||
let mut cookie_pair = CookiePair::new("foo".to_string(), "bar".to_string());
|
let mut cookie_pair = CookiePair::new("foo".to_owned(), "bar".to_owned());
|
||||||
cookie_pair.httponly = true;
|
cookie_pair.httponly = true;
|
||||||
cookie_pair.path = Some("/p".to_string());
|
cookie_pair.path = Some("/p".to_owned());
|
||||||
let cookie_header = Cookie(vec![
|
let cookie_header = Cookie(vec![
|
||||||
cookie_pair,
|
cookie_pair,
|
||||||
CookiePair::new("baz".to_string(),"quux".to_string())]);
|
CookiePair::new("baz".to_owned(),"quux".to_owned())]);
|
||||||
let mut headers = Headers::new();
|
let mut headers = Headers::new();
|
||||||
headers.set(cookie_header);
|
headers.set(cookie_header);
|
||||||
|
|
||||||
@@ -109,7 +109,7 @@ fn test_fmt() {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn cookie_jar() {
|
fn cookie_jar() {
|
||||||
let cookie_pair = CookiePair::new("foo".to_string(), "bar".to_string());
|
let cookie_pair = CookiePair::new("foo".to_owned(), "bar".to_owned());
|
||||||
let cookie_header = Cookie(vec![cookie_pair]);
|
let cookie_header = Cookie(vec![cookie_pair]);
|
||||||
let jar = cookie_header.to_cookie_jar(&[]);
|
let jar = cookie_header.to_cookie_jar(&[]);
|
||||||
let new_cookie_header = Cookie::from_cookie_jar(&jar);
|
let new_cookie_header = Cookie::from_cookie_jar(&jar);
|
||||||
|
|||||||
@@ -28,29 +28,29 @@ header! {
|
|||||||
// From the RFC
|
// From the RFC
|
||||||
test_header!(test1,
|
test_header!(test1,
|
||||||
vec![b"\"xyzzy\""],
|
vec![b"\"xyzzy\""],
|
||||||
Some(ETag(EntityTag::new(false, "xyzzy".to_string()))));
|
Some(ETag(EntityTag::new(false, "xyzzy".to_owned()))));
|
||||||
test_header!(test2,
|
test_header!(test2,
|
||||||
vec![b"W/\"xyzzy\""],
|
vec![b"W/\"xyzzy\""],
|
||||||
Some(ETag(EntityTag::new(true, "xyzzy".to_string()))));
|
Some(ETag(EntityTag::new(true, "xyzzy".to_owned()))));
|
||||||
test_header!(test3,
|
test_header!(test3,
|
||||||
vec![b"\"\""],
|
vec![b"\"\""],
|
||||||
Some(ETag(EntityTag::new(false, "".to_string()))));
|
Some(ETag(EntityTag::new(false, "".to_owned()))));
|
||||||
// Own tests
|
// Own tests
|
||||||
test_header!(test4,
|
test_header!(test4,
|
||||||
vec![b"\"foobar\""],
|
vec![b"\"foobar\""],
|
||||||
Some(ETag(EntityTag::new(false, "foobar".to_string()))));
|
Some(ETag(EntityTag::new(false, "foobar".to_owned()))));
|
||||||
test_header!(test5,
|
test_header!(test5,
|
||||||
vec![b"\"\""],
|
vec![b"\"\""],
|
||||||
Some(ETag(EntityTag::new(false, "".to_string()))));
|
Some(ETag(EntityTag::new(false, "".to_owned()))));
|
||||||
test_header!(test6,
|
test_header!(test6,
|
||||||
vec![b"W/\"weak-etag\""],
|
vec![b"W/\"weak-etag\""],
|
||||||
Some(ETag(EntityTag::new(true, "weak-etag".to_string()))));
|
Some(ETag(EntityTag::new(true, "weak-etag".to_owned()))));
|
||||||
test_header!(test7,
|
test_header!(test7,
|
||||||
vec![b"W/\"\x65\x62\""],
|
vec![b"W/\"\x65\x62\""],
|
||||||
Some(ETag(EntityTag::new(true, "\u{0065}\u{0062}".to_string()))));
|
Some(ETag(EntityTag::new(true, "\u{0065}\u{0062}".to_owned()))));
|
||||||
test_header!(test8,
|
test_header!(test8,
|
||||||
vec![b"W/\"\""],
|
vec![b"W/\"\""],
|
||||||
Some(ETag(EntityTag::new(true, "".to_string()))));
|
Some(ETag(EntityTag::new(true, "".to_owned()))));
|
||||||
test_header!(test9,
|
test_header!(test9,
|
||||||
vec![b"no-dquotes"],
|
vec![b"no-dquotes"],
|
||||||
None::<ETag>);
|
None::<ETag>);
|
||||||
|
|||||||
@@ -83,14 +83,14 @@ mod tests {
|
|||||||
fn test_host() {
|
fn test_host() {
|
||||||
let host = Header::parse_header([b"foo.com".to_vec()].as_ref());
|
let host = Header::parse_header([b"foo.com".to_vec()].as_ref());
|
||||||
assert_eq!(host, Some(Host {
|
assert_eq!(host, Some(Host {
|
||||||
hostname: "foo.com".to_string(),
|
hostname: "foo.com".to_owned(),
|
||||||
port: None
|
port: None
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
|
||||||
let host = Header::parse_header([b"foo.com:8080".to_vec()].as_ref());
|
let host = Header::parse_header([b"foo.com:8080".to_vec()].as_ref());
|
||||||
assert_eq!(host, Some(Host {
|
assert_eq!(host, Some(Host {
|
||||||
hostname: "foo.com".to_string(),
|
hostname: "foo.com".to_owned(),
|
||||||
port: Some(8080)
|
port: Some(8080)
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,14 +31,14 @@ header! {
|
|||||||
test1,
|
test1,
|
||||||
vec![b"\"xyzzy\""],
|
vec![b"\"xyzzy\""],
|
||||||
Some(HeaderField::Items(
|
Some(HeaderField::Items(
|
||||||
vec![EntityTag::new(false, "xyzzy".to_string())])));
|
vec![EntityTag::new(false, "xyzzy".to_owned())])));
|
||||||
test_header!(
|
test_header!(
|
||||||
test2,
|
test2,
|
||||||
vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""],
|
vec![b"\"xyzzy\", \"r2d2xxxx\", \"c3piozzzz\""],
|
||||||
Some(HeaderField::Items(
|
Some(HeaderField::Items(
|
||||||
vec![EntityTag::new(false, "xyzzy".to_string()),
|
vec![EntityTag::new(false, "xyzzy".to_owned()),
|
||||||
EntityTag::new(false, "r2d2xxxx".to_string()),
|
EntityTag::new(false, "r2d2xxxx".to_owned()),
|
||||||
EntityTag::new(false, "c3piozzzz".to_string())])));
|
EntityTag::new(false, "c3piozzzz".to_owned())])));
|
||||||
test_header!(test3, vec![b"*"], Some(IfMatch::Any));
|
test_header!(test3, vec![b"*"], Some(IfMatch::Any));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,8 +52,8 @@ mod tests {
|
|||||||
|
|
||||||
if_none_match = Header::parse_header([b"\"foobar\", W/\"weak-etag\"".to_vec()].as_ref());
|
if_none_match = Header::parse_header([b"\"foobar\", W/\"weak-etag\"".to_vec()].as_ref());
|
||||||
let mut entities: Vec<EntityTag> = Vec::new();
|
let mut entities: Vec<EntityTag> = Vec::new();
|
||||||
let foobar_etag = EntityTag::new(false, "foobar".to_string());
|
let foobar_etag = EntityTag::new(false, "foobar".to_owned());
|
||||||
let weak_etag = EntityTag::new(true, "weak-etag".to_string());
|
let weak_etag = EntityTag::new(true, "weak-etag".to_owned());
|
||||||
entities.push(foobar_etag);
|
entities.push(foobar_etag);
|
||||||
entities.push(weak_etag);
|
entities.push(weak_etag);
|
||||||
assert_eq!(if_none_match, Some(IfNoneMatch::Items(entities)));
|
assert_eq!(if_none_match, Some(IfNoneMatch::Items(entities)));
|
||||||
|
|||||||
@@ -128,12 +128,12 @@ macro_rules! test_header {
|
|||||||
let result_cmp: Vec<String> = result
|
let result_cmp: Vec<String> = result
|
||||||
.to_ascii_lowercase()
|
.to_ascii_lowercase()
|
||||||
.split(' ')
|
.split(' ')
|
||||||
.map(|x| x.to_string())
|
.map(|x| x.to_owned())
|
||||||
.collect();
|
.collect();
|
||||||
let expected_cmp: Vec<String> = expected
|
let expected_cmp: Vec<String> = expected
|
||||||
.to_ascii_lowercase()
|
.to_ascii_lowercase()
|
||||||
.split(' ')
|
.split(' ')
|
||||||
.map(|x| x.to_string())
|
.map(|x| x.to_owned())
|
||||||
.collect();
|
.collect();
|
||||||
assert_eq!(result_cmp.concat(), expected_cmp.concat());
|
assert_eq!(result_cmp.concat(), expected_cmp.concat());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,7 +55,7 @@ fn test_parse_header() {
|
|||||||
let b = Pragma::NoCache;
|
let b = Pragma::NoCache;
|
||||||
assert_eq!(a, b);
|
assert_eq!(a, b);
|
||||||
let c: Pragma = Header::parse_header([b"FoObar".to_vec()].as_ref()).unwrap();
|
let c: Pragma = Header::parse_header([b"FoObar".to_vec()].as_ref()).unwrap();
|
||||||
let d = Pragma::Ext("FoObar".to_string());
|
let d = Pragma::Ext("FoObar".to_owned());
|
||||||
assert_eq!(c, d);
|
assert_eq!(c, d);
|
||||||
let e: Option<Pragma> = Header::parse_header([b"".to_vec()].as_ref());
|
let e: Option<Pragma> = Header::parse_header([b"".to_vec()].as_ref());
|
||||||
assert_eq!(e, None);
|
assert_eq!(e, None);
|
||||||
|
|||||||
@@ -117,7 +117,7 @@ impl SetCookie {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_parse() {
|
fn test_parse() {
|
||||||
let h = Header::parse_header(&[b"foo=bar; HttpOnly".to_vec()][..]);
|
let h = Header::parse_header(&[b"foo=bar; HttpOnly".to_vec()][..]);
|
||||||
let mut c1 = Cookie::new("foo".to_string(), "bar".to_string());
|
let mut c1 = Cookie::new("foo".to_owned(), "bar".to_owned());
|
||||||
c1.httponly = true;
|
c1.httponly = true;
|
||||||
|
|
||||||
assert_eq!(h, Some(SetCookie(vec![c1])));
|
assert_eq!(h, Some(SetCookie(vec![c1])));
|
||||||
@@ -127,10 +127,10 @@ fn test_parse() {
|
|||||||
fn test_fmt() {
|
fn test_fmt() {
|
||||||
use header::Headers;
|
use header::Headers;
|
||||||
|
|
||||||
let mut cookie = Cookie::new("foo".to_string(), "bar".to_string());
|
let mut cookie = Cookie::new("foo".to_owned(), "bar".to_owned());
|
||||||
cookie.httponly = true;
|
cookie.httponly = true;
|
||||||
cookie.path = Some("/p".to_string());
|
cookie.path = Some("/p".to_owned());
|
||||||
let cookies = SetCookie(vec![cookie, Cookie::new("baz".to_string(), "quux".to_string())]);
|
let cookies = SetCookie(vec![cookie, Cookie::new("baz".to_owned(), "quux".to_owned())]);
|
||||||
let mut headers = Headers::new();
|
let mut headers = Headers::new();
|
||||||
headers.set(cookies);
|
headers.set(cookies);
|
||||||
|
|
||||||
@@ -142,7 +142,7 @@ fn test_fmt() {
|
|||||||
#[test]
|
#[test]
|
||||||
fn cookie_jar() {
|
fn cookie_jar() {
|
||||||
let jar = CookieJar::new(b"secret");
|
let jar = CookieJar::new(b"secret");
|
||||||
let cookie = Cookie::new("foo".to_string(), "bar".to_string());
|
let cookie = Cookie::new("foo".to_owned(), "bar".to_owned());
|
||||||
jar.encrypted().add(cookie);
|
jar.encrypted().add(cookie);
|
||||||
|
|
||||||
let cookies = SetCookie::from_cookie_jar(&jar);
|
let cookies = SetCookie::from_cookie_jar(&jar);
|
||||||
|
|||||||
@@ -34,10 +34,10 @@ header! {
|
|||||||
test1,
|
test1,
|
||||||
vec![b"HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11"],
|
vec![b"HTTP/2.0, SHTTP/1.3, IRC/6.9, RTA/x11"],
|
||||||
Some(Upgrade(vec![
|
Some(Upgrade(vec![
|
||||||
Protocol::new(ProtocolName::Http, Some("2.0".to_string())),
|
Protocol::new(ProtocolName::Http, Some("2.0".to_owned())),
|
||||||
Protocol::new(ProtocolName::Unregistered("SHTTP".to_string()), Some("1.3".to_string())),
|
Protocol::new(ProtocolName::Unregistered("SHTTP".to_owned()), Some("1.3".to_owned())),
|
||||||
Protocol::new(ProtocolName::Unregistered("IRC".to_string()), Some("6.9".to_string())),
|
Protocol::new(ProtocolName::Unregistered("IRC".to_owned()), Some("6.9".to_owned())),
|
||||||
Protocol::new(ProtocolName::Unregistered("RTA".to_string()), Some("x11".to_string())),
|
Protocol::new(ProtocolName::Unregistered("RTA".to_owned()), Some("x11".to_owned())),
|
||||||
])));
|
])));
|
||||||
// Own tests
|
// Own tests
|
||||||
test_header!(
|
test_header!(
|
||||||
@@ -79,7 +79,7 @@ impl FromStr for ProtocolName {
|
|||||||
if UniCase(s) == UniCase("websocket") {
|
if UniCase(s) == UniCase("websocket") {
|
||||||
ProtocolName::WebSocket
|
ProtocolName::WebSocket
|
||||||
} else {
|
} else {
|
||||||
ProtocolName::Unregistered(s.to_string())
|
ProtocolName::Unregistered(s.to_owned())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -118,7 +118,7 @@ impl FromStr for Protocol {
|
|||||||
type Err =();
|
type Err =();
|
||||||
fn from_str(s: &str) -> Result<Protocol, ()> {
|
fn from_str(s: &str) -> Result<Protocol, ()> {
|
||||||
let mut parts = s.splitn(2, '/');
|
let mut parts = s.splitn(2, '/');
|
||||||
Ok(Protocol::new(try!(parts.next().unwrap().parse()), parts.next().map(|x| x.to_string())))
|
Ok(Protocol::new(try!(parts.next().unwrap().parse()), parts.next().map(|x| x.to_owned())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -29,6 +29,6 @@ header! {
|
|||||||
// 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
|
// Own testcase
|
||||||
test_header!(test2, vec![b"Bunnies"], Some(UserAgent("Bunnies".to_string())));
|
test_header!(test2, vec![b"Bunnies"], Some(UserAgent("Bunnies".to_owned())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -503,7 +503,7 @@ mod tests {
|
|||||||
fn test_headers_show() {
|
fn test_headers_show() {
|
||||||
let mut headers = Headers::new();
|
let mut headers = Headers::new();
|
||||||
headers.set(ContentLength(15));
|
headers.set(ContentLength(15));
|
||||||
headers.set(Host { hostname: "foo.bar".to_string(), port: None });
|
headers.set(Host { hostname: "foo.bar".to_owned(), port: None });
|
||||||
|
|
||||||
let s = headers.to_string();
|
let s = headers.to_string();
|
||||||
// hashmap's iterators have arbitrary order, so we must sort first
|
// hashmap's iterators have arbitrary order, so we must sort first
|
||||||
@@ -567,7 +567,7 @@ mod tests {
|
|||||||
assert!(header.is::<ContentLength>());
|
assert!(header.is::<ContentLength>());
|
||||||
assert_eq!(header.name(), <ContentLength as Header>::header_name());
|
assert_eq!(header.name(), <ContentLength as Header>::header_name());
|
||||||
assert_eq!(header.value(), Some(&ContentLength(11)));
|
assert_eq!(header.value(), Some(&ContentLength(11)));
|
||||||
assert_eq!(header.value_string(), "11".to_string());
|
assert_eq!(header.value_string(), "11".to_owned());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ impl FromStr for Charset {
|
|||||||
"GB2312" => Gb2312,
|
"GB2312" => Gb2312,
|
||||||
"5" => Big5,
|
"5" => Big5,
|
||||||
"KOI8-R" => Koi8_R,
|
"KOI8-R" => Koi8_R,
|
||||||
s => Ext(s.to_string())
|
s => Ext(s.to_owned())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -141,11 +141,11 @@ fn test_parse() {
|
|||||||
assert_eq!(Us_Ascii,"US-Ascii".parse().unwrap());
|
assert_eq!(Us_Ascii,"US-Ascii".parse().unwrap());
|
||||||
assert_eq!(Us_Ascii,"US-ASCII".parse().unwrap());
|
assert_eq!(Us_Ascii,"US-ASCII".parse().unwrap());
|
||||||
assert_eq!(Shift_Jis,"Shift-JIS".parse().unwrap());
|
assert_eq!(Shift_Jis,"Shift-JIS".parse().unwrap());
|
||||||
assert_eq!(Ext("ABCD".to_string()),"abcd".parse().unwrap());
|
assert_eq!(Ext("ABCD".to_owned()),"abcd".parse().unwrap());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_display() {
|
fn test_display() {
|
||||||
assert_eq!("US-ASCII", format!("{}", Us_Ascii));
|
assert_eq!("US-ASCII", format!("{}", Us_Ascii));
|
||||||
assert_eq!("ABCD", format!("{}", Ext("ABCD".to_string())));
|
assert_eq!("ABCD", format!("{}", Ext("ABCD".to_owned())));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ impl str::FromStr for Encoding {
|
|||||||
"gzip" => Ok(Gzip),
|
"gzip" => Ok(Gzip),
|
||||||
"compress" => Ok(Compress),
|
"compress" => Ok(Compress),
|
||||||
"identity" => Ok(Identity),
|
"identity" => Ok(Identity),
|
||||||
_ => Ok(EncodingExt(s.to_string()))
|
_ => Ok(EncodingExt(s.to_owned()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -119,9 +119,9 @@ impl FromStr for EntityTag {
|
|||||||
if slice.starts_with('"') && check_slice_validity(&slice[1..length-1]) {
|
if slice.starts_with('"') && check_slice_validity(&slice[1..length-1]) {
|
||||||
// No need to check if the last char is a DQUOTE,
|
// No need to check if the last char is a DQUOTE,
|
||||||
// we already did that above.
|
// we already did that above.
|
||||||
return Ok(EntityTag { weak: false, tag: slice[1..length-1].to_string() });
|
return Ok(EntityTag { weak: false, tag: slice[1..length-1].to_owned() });
|
||||||
} else if slice.starts_with("W/\"") && check_slice_validity(&slice[3..length-1]) {
|
} else if slice.starts_with("W/\"") && check_slice_validity(&slice[3..length-1]) {
|
||||||
return Ok(EntityTag { weak: true, tag: slice[3..length-1].to_string() });
|
return Ok(EntityTag { weak: true, tag: slice[3..length-1].to_owned() });
|
||||||
}
|
}
|
||||||
Err(())
|
Err(())
|
||||||
}
|
}
|
||||||
@@ -134,11 +134,11 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_etag_parse_success() {
|
fn test_etag_parse_success() {
|
||||||
// Expected success
|
// Expected success
|
||||||
assert_eq!("\"foobar\"".parse::<EntityTag>().unwrap(), EntityTag::new(false, "foobar".to_string()));
|
assert_eq!("\"foobar\"".parse::<EntityTag>().unwrap(), EntityTag::new(false, "foobar".to_owned()));
|
||||||
assert_eq!("\"\"".parse::<EntityTag>().unwrap(), EntityTag::new(false, "".to_string()));
|
assert_eq!("\"\"".parse::<EntityTag>().unwrap(), EntityTag::new(false, "".to_owned()));
|
||||||
assert_eq!("W/\"weaktag\"".parse::<EntityTag>().unwrap(), EntityTag::new(true, "weaktag".to_string()));
|
assert_eq!("W/\"weaktag\"".parse::<EntityTag>().unwrap(), EntityTag::new(true, "weaktag".to_owned()));
|
||||||
assert_eq!("W/\"\x65\x62\"".parse::<EntityTag>().unwrap(), EntityTag::new(true, "\x65\x62".to_string()));
|
assert_eq!("W/\"\x65\x62\"".parse::<EntityTag>().unwrap(), EntityTag::new(true, "\x65\x62".to_owned()));
|
||||||
assert_eq!("W/\"\"".parse::<EntityTag>().unwrap(), EntityTag::new(true, "".to_string()));
|
assert_eq!("W/\"\"".parse::<EntityTag>().unwrap(), EntityTag::new(true, "".to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -154,11 +154,11 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_etag_fmt() {
|
fn test_etag_fmt() {
|
||||||
assert_eq!(format!("{}", EntityTag::new(false, "foobar".to_string())), "\"foobar\"");
|
assert_eq!(format!("{}", EntityTag::new(false, "foobar".to_owned())), "\"foobar\"");
|
||||||
assert_eq!(format!("{}", EntityTag::new(false, "".to_string())), "\"\"");
|
assert_eq!(format!("{}", EntityTag::new(false, "".to_owned())), "\"\"");
|
||||||
assert_eq!(format!("{}", EntityTag::new(true, "weak-etag".to_string())), "W/\"weak-etag\"");
|
assert_eq!(format!("{}", EntityTag::new(true, "weak-etag".to_owned())), "W/\"weak-etag\"");
|
||||||
assert_eq!(format!("{}", EntityTag::new(true, "\u{0065}".to_string())), "W/\"\x65\"");
|
assert_eq!(format!("{}", EntityTag::new(true, "\u{0065}".to_owned())), "W/\"\x65\"");
|
||||||
assert_eq!(format!("{}", EntityTag::new(true, "".to_string())), "W/\"\"");
|
assert_eq!(format!("{}", EntityTag::new(true, "".to_owned())), "W/\"\"");
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -169,29 +169,29 @@ mod tests {
|
|||||||
// | `W/"1"` | `W/"2"` | no match | no match |
|
// | `W/"1"` | `W/"2"` | no match | no match |
|
||||||
// | `W/"1"` | `"1"` | no match | match |
|
// | `W/"1"` | `"1"` | no match | match |
|
||||||
// | `"1"` | `"1"` | match | match |
|
// | `"1"` | `"1"` | match | match |
|
||||||
let mut etag1 = EntityTag::new(true, "1".to_string());
|
let mut etag1 = EntityTag::new(true, "1".to_owned());
|
||||||
let mut etag2 = EntityTag::new(true, "1".to_string());
|
let mut etag2 = EntityTag::new(true, "1".to_owned());
|
||||||
assert_eq!(etag1.strong_eq(&etag2), false);
|
assert_eq!(etag1.strong_eq(&etag2), false);
|
||||||
assert_eq!(etag1.weak_eq(&etag2), true);
|
assert_eq!(etag1.weak_eq(&etag2), true);
|
||||||
assert_eq!(etag1.strong_ne(&etag2), true);
|
assert_eq!(etag1.strong_ne(&etag2), true);
|
||||||
assert_eq!(etag1.weak_ne(&etag2), false);
|
assert_eq!(etag1.weak_ne(&etag2), false);
|
||||||
|
|
||||||
etag1 = EntityTag::new(true, "1".to_string());
|
etag1 = EntityTag::new(true, "1".to_owned());
|
||||||
etag2 = EntityTag::new(true, "2".to_string());
|
etag2 = EntityTag::new(true, "2".to_owned());
|
||||||
assert_eq!(etag1.strong_eq(&etag2), false);
|
assert_eq!(etag1.strong_eq(&etag2), false);
|
||||||
assert_eq!(etag1.weak_eq(&etag2), false);
|
assert_eq!(etag1.weak_eq(&etag2), false);
|
||||||
assert_eq!(etag1.strong_ne(&etag2), true);
|
assert_eq!(etag1.strong_ne(&etag2), true);
|
||||||
assert_eq!(etag1.weak_ne(&etag2), true);
|
assert_eq!(etag1.weak_ne(&etag2), true);
|
||||||
|
|
||||||
etag1 = EntityTag::new(true, "1".to_string());
|
etag1 = EntityTag::new(true, "1".to_owned());
|
||||||
etag2 = EntityTag::new(false, "1".to_string());
|
etag2 = EntityTag::new(false, "1".to_owned());
|
||||||
assert_eq!(etag1.strong_eq(&etag2), false);
|
assert_eq!(etag1.strong_eq(&etag2), false);
|
||||||
assert_eq!(etag1.weak_eq(&etag2), true);
|
assert_eq!(etag1.weak_eq(&etag2), true);
|
||||||
assert_eq!(etag1.strong_ne(&etag2), true);
|
assert_eq!(etag1.strong_ne(&etag2), true);
|
||||||
assert_eq!(etag1.weak_ne(&etag2), false);
|
assert_eq!(etag1.weak_ne(&etag2), false);
|
||||||
|
|
||||||
etag1 = EntityTag::new(false, "1".to_string());
|
etag1 = EntityTag::new(false, "1".to_owned());
|
||||||
etag2 = EntityTag::new(false, "1".to_string());
|
etag2 = EntityTag::new(false, "1".to_owned());
|
||||||
assert_eq!(etag1.strong_eq(&etag2), true);
|
assert_eq!(etag1.strong_eq(&etag2), true);
|
||||||
assert_eq!(etag1.weak_eq(&etag2), true);
|
assert_eq!(etag1.weak_eq(&etag2), true);
|
||||||
assert_eq!(etag1.strong_ne(&etag2), false);
|
assert_eq!(etag1.strong_ne(&etag2), false);
|
||||||
|
|||||||
@@ -22,11 +22,11 @@ impl FromStr for Language {
|
|||||||
let s = i.next();
|
let s = i.next();
|
||||||
match (p, s) {
|
match (p, s) {
|
||||||
(Some(p), Some(s)) => Ok(Language {
|
(Some(p), Some(s)) => Ok(Language {
|
||||||
primary: p.to_string(),
|
primary: p.to_owned(),
|
||||||
sub: Some(s.to_string())
|
sub: Some(s.to_owned())
|
||||||
}),
|
}),
|
||||||
(Some(p), _) => Ok(Language {
|
(Some(p), _) => Ok(Language {
|
||||||
primary: p.to_string(),
|
primary: p.to_owned(),
|
||||||
sub: None
|
sub: None
|
||||||
}),
|
}),
|
||||||
_ => Err(())
|
_ => Err(())
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ mod tests {
|
|||||||
fn test_quality_item_show3() {
|
fn test_quality_item_show3() {
|
||||||
// Custom value
|
// Custom value
|
||||||
let x = QualityItem{
|
let x = QualityItem{
|
||||||
item: EncodingExt("identity".to_string()),
|
item: EncodingExt("identity".to_owned()),
|
||||||
quality: Quality(500),
|
quality: Quality(500),
|
||||||
};
|
};
|
||||||
assert_eq!(format!("{}", x), "identity; q=0.5");
|
assert_eq!(format!("{}", x), "identity; q=0.5");
|
||||||
|
|||||||
@@ -102,7 +102,7 @@ impl FromStr for Method {
|
|||||||
"TRACE" => Trace,
|
"TRACE" => Trace,
|
||||||
"CONNECT" => Connect,
|
"CONNECT" => Connect,
|
||||||
"PATCH" => Patch,
|
"PATCH" => Patch,
|
||||||
_ => Extension(s.to_string())
|
_ => Extension(s.to_owned())
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,7 +149,7 @@ mod tests {
|
|||||||
#[test]
|
#[test]
|
||||||
fn test_from_str() {
|
fn test_from_str() {
|
||||||
assert_eq!(Get, FromStr::from_str("GET").unwrap());
|
assert_eq!(Get, FromStr::from_str("GET").unwrap());
|
||||||
assert_eq!(Extension("MOVE".to_string()),
|
assert_eq!(Extension("MOVE".to_owned()),
|
||||||
FromStr::from_str("MOVE").unwrap());
|
FromStr::from_str("MOVE").unwrap());
|
||||||
let x: Result<Method, _> = FromStr::from_str("");
|
let x: Result<Method, _> = FromStr::from_str("");
|
||||||
if let Err(Error::Method) = x {
|
if let Err(Error::Method) = x {
|
||||||
@@ -160,9 +160,9 @@ mod tests {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_fmt() {
|
fn test_fmt() {
|
||||||
assert_eq!("GET".to_string(), format!("{}", Get));
|
assert_eq!("GET".to_owned(), format!("{}", Get));
|
||||||
assert_eq!("MOVE".to_string(),
|
assert_eq!("MOVE".to_owned(),
|
||||||
format!("{}", Extension("MOVE".to_string())));
|
format!("{}", Extension("MOVE".to_owned())));
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -177,6 +177,6 @@ mod tests {
|
|||||||
assert_eq!(Get.as_ref(), "GET");
|
assert_eq!(Get.as_ref(), "GET");
|
||||||
assert_eq!(Post.as_ref(), "POST");
|
assert_eq!(Post.as_ref(), "POST");
|
||||||
assert_eq!(Put.as_ref(), "PUT");
|
assert_eq!(Put.as_ref(), "PUT");
|
||||||
assert_eq!(Extension("MOVE".to_string()).as_ref(), "MOVE");
|
assert_eq!(Extension("MOVE".to_owned()).as_ref(), "MOVE");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,9 +133,9 @@ macro_rules! mock_connector (
|
|||||||
let key = format!("{}://{}", scheme, host);
|
let key = format!("{}://{}", scheme, host);
|
||||||
// ignore port for now
|
// ignore port for now
|
||||||
match map.get(&*key) {
|
match map.get(&*key) {
|
||||||
Some(res) => Ok($crate::mock::MockStream {
|
Some(&res) => Ok($crate::mock::MockStream {
|
||||||
write: vec![],
|
write: vec![],
|
||||||
read: Cursor::new(res.to_string().into_bytes()),
|
read: Cursor::new(res.to_owned().into_bytes()),
|
||||||
}),
|
}),
|
||||||
None => panic!("{:?} doesn't know url {}", stringify!($name), key)
|
None => panic!("{:?} doesn't know url {}", stringify!($name), key)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -114,7 +114,7 @@ mod tests {
|
|||||||
let mut stream = BufReader::new(mock);
|
let mut stream = BufReader::new(mock);
|
||||||
|
|
||||||
let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap();
|
let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap();
|
||||||
assert_eq!(read_to_string(req).unwrap(), "".to_string());
|
assert_eq!(read_to_string(req).unwrap(), "".to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -131,7 +131,7 @@ mod tests {
|
|||||||
let mut stream = BufReader::new(mock);
|
let mut stream = BufReader::new(mock);
|
||||||
|
|
||||||
let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap();
|
let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap();
|
||||||
assert_eq!(read_to_string(req).unwrap(), "".to_string());
|
assert_eq!(read_to_string(req).unwrap(), "".to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -148,7 +148,7 @@ mod tests {
|
|||||||
let mut stream = BufReader::new(mock);
|
let mut stream = BufReader::new(mock);
|
||||||
|
|
||||||
let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap();
|
let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap();
|
||||||
assert_eq!(read_to_string(req).unwrap(), "".to_string());
|
assert_eq!(read_to_string(req).unwrap(), "".to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -189,7 +189,7 @@ mod tests {
|
|||||||
None => panic!("Transfer-Encoding: chunked expected!"),
|
None => panic!("Transfer-Encoding: chunked expected!"),
|
||||||
};
|
};
|
||||||
// The content is correctly read?
|
// The content is correctly read?
|
||||||
assert_eq!(read_to_string(req).unwrap(), "qwert".to_string());
|
assert_eq!(read_to_string(req).unwrap(), "qwert".to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Tests that when a chunk size is not a valid radix-16 number, an error
|
/// Tests that when a chunk size is not a valid radix-16 number, an error
|
||||||
@@ -261,7 +261,7 @@ mod tests {
|
|||||||
|
|
||||||
let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap();
|
let req = Request::new(&mut stream, sock("127.0.0.1:80")).unwrap();
|
||||||
|
|
||||||
assert_eq!(read_to_string(req).unwrap(), "1".to_string());
|
assert_eq!(read_to_string(req).unwrap(), "1".to_owned());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/uri.rs
10
src/uri.rs
@@ -59,15 +59,15 @@ impl FromStr for RequestUri {
|
|||||||
} else if bytes == b"*" {
|
} else if bytes == b"*" {
|
||||||
Ok(RequestUri::Star)
|
Ok(RequestUri::Star)
|
||||||
} else if bytes.starts_with(b"/") {
|
} else if bytes.starts_with(b"/") {
|
||||||
Ok(RequestUri::AbsolutePath(s.to_string()))
|
Ok(RequestUri::AbsolutePath(s.to_owned()))
|
||||||
} else if bytes.contains(&b'/') {
|
} else if bytes.contains(&b'/') {
|
||||||
Ok(RequestUri::AbsoluteUri(try!(Url::parse(s))))
|
Ok(RequestUri::AbsoluteUri(try!(Url::parse(s))))
|
||||||
} else {
|
} else {
|
||||||
let mut temp = "http://".to_string();
|
let mut temp = "http://".to_owned();
|
||||||
temp.push_str(s);
|
temp.push_str(s);
|
||||||
try!(Url::parse(&temp[..]));
|
try!(Url::parse(&temp[..]));
|
||||||
todo!("compare vs u.authority()");
|
todo!("compare vs u.authority()");
|
||||||
Ok(RequestUri::Authority(s.to_string()))
|
Ok(RequestUri::Authority(s.to_owned()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,8 +80,8 @@ fn test_uri_fromstr() {
|
|||||||
|
|
||||||
read("*", RequestUri::Star);
|
read("*", RequestUri::Star);
|
||||||
read("http://hyper.rs/", RequestUri::AbsoluteUri(Url::parse("http://hyper.rs/").unwrap()));
|
read("http://hyper.rs/", RequestUri::AbsoluteUri(Url::parse("http://hyper.rs/").unwrap()));
|
||||||
read("hyper.rs", RequestUri::Authority("hyper.rs".to_string()));
|
read("hyper.rs", RequestUri::Authority("hyper.rs".to_owned()));
|
||||||
read("/", RequestUri::AbsolutePath("/".to_string()));
|
read("/", RequestUri::AbsolutePath("/".to_owned()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user