diff options
Diffstat (limited to 'components/net/cookie.rs')
-rw-r--r-- | components/net/cookie.rs | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/components/net/cookie.rs b/components/net/cookie.rs index 2f555767b11..e85f0b41397 100644 --- a/components/net/cookie.rs +++ b/components/net/cookie.rs @@ -16,7 +16,7 @@ use url::Url; /// A stored cookie that wraps the definition in cookie-rs. This is used to implement /// various behaviours defined in the spec that rely on an associated request URL, /// which cookie-rs and hyper's header parsing do not support. -#[derive(Clone, Debug)] +#[derive(Clone, Debug, RustcDecodable, RustcEncodable)] pub struct Cookie { pub cookie: cookie_rs::Cookie, pub host_only: bool, @@ -39,7 +39,7 @@ impl Cookie { _ => (false, None) }; - let url_host = request.host().map_or("".to_owned(), |host| host.serialize()); + let url_host = request.host_str().unwrap_or("").to_owned(); // Step 4 let mut domain = cookie.domain.clone().unwrap_or("".to_owned()); @@ -66,10 +66,8 @@ impl Cookie { // Step 7 let mut path = cookie.path.unwrap_or("".to_owned()); - if path.is_empty() || path.as_bytes()[0] != b'/' { - let url_path = request.serialize_path(); - let url_path = url_path.as_ref().map(|path| &**path); - path = Cookie::default_path(url_path.unwrap_or("")).to_owned(); + if path.chars().next() != Some('/') { + path = Cookie::default_path(request.path()).to_owned(); } cookie.path = Some(path); @@ -96,7 +94,7 @@ impl Cookie { // http://tools.ietf.org/html/rfc6265#section-5.1.4 pub fn default_path(request_path: &str) -> &str { // Step 2 - if request_path.is_empty() || !request_path.starts_with("/") { + if request_path.chars().next() != Some('/') { return "/"; } @@ -135,10 +133,10 @@ impl Cookie { if string == domain_string { return true; } - if string.ends_with(domain_string) - && string.as_bytes()[string.len()-domain_string.len()-1] == b'.' - && string.parse::<Ipv4Addr>().is_err() - && string.parse::<Ipv6Addr>().is_err() { + if string.ends_with(domain_string) && + string.as_bytes()[string.len()-domain_string.len()-1] == b'.' && + string.parse::<Ipv4Addr>().is_err() && + string.parse::<Ipv6Addr>().is_err() { return true; } false @@ -146,26 +144,26 @@ impl Cookie { // http://tools.ietf.org/html/rfc6265#section-5.4 step 1 pub fn appropriate_for_url(&self, url: &Url, source: CookieSource) -> bool { - let domain = url.host().map(|host| host.serialize()); + let domain = url.host_str(); if self.host_only { - if self.cookie.domain != domain { + if self.cookie.domain.as_ref().map(String::as_str) != domain { return false; } } else { - if let (Some(ref domain), &Some(ref cookie_domain)) = (domain, &self.cookie.domain) { + if let (Some(domain), &Some(ref cookie_domain)) = (domain, &self.cookie.domain) { if !Cookie::domain_match(domain, cookie_domain) { return false; } } } - if let (Some(ref path), &Some(ref cookie_path)) = (url.serialize_path(), &self.cookie.path) { - if !Cookie::path_match(path, cookie_path) { + if let Some(ref cookie_path) = self.cookie.path { + if !Cookie::path_match(url.path(), cookie_path) { return false; } } - if self.cookie.secure && url.scheme != "https" { + if self.cookie.secure && url.scheme() != "https" { return false; } if self.cookie.httponly && source == CookieSource::NonHTTP { |