Skip to content

Commit

Permalink
Conform conditionals regarding cookie removal with spec
Browse files Browse the repository at this point in the history
  • Loading branch information
KiChjang committed Dec 20, 2016
1 parent fd5733f commit 64b456f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions components/net/cookie_storage.rs
Expand Up @@ -37,23 +37,24 @@ impl CookieStorage {
let domain = reg_host(cookie.cookie.domain.as_ref().unwrap_or(&"".to_string()));
let cookies = self.cookies_map.entry(domain).or_insert(vec![]);

// Step 1
// Step 11.1
let position = cookies.iter().position(|c| {
c.cookie.domain == cookie.cookie.domain &&
c.cookie.path == cookie.cookie.path &&
c.cookie.name == cookie.cookie.name
});

if let Some(ind) = position {
// Step 11.4
let c = cookies.remove(ind);

// http://tools.ietf.org/html/rfc6265#section-5.3 step 11.2
if !c.cookie.httponly || source == CookieSource::HTTP {
Ok(Some(c))
} else {
if c.cookie.httponly && source == CookieSource::NonHTTP {
// Undo the removal.
cookies.push(c);
Err(())
} else {
Ok(Some(c))
}
} else {
Ok(None)
Expand Down Expand Up @@ -83,7 +84,7 @@ impl CookieStorage {
cookies.retain(|c| !is_cookie_expired(&c));
let new_len = cookies.len();

// https://datatracker.ietf.org/doc/draft-ietf-httpbis-cookie-alone
// https://www.ietf.org/id/draft-ietf-httpbis-cookie-alone-01.txt
if new_len == old_len && !evict_one_cookie(cookie.cookie.secure, cookies) {
return;
}
Expand Down Expand Up @@ -159,6 +160,7 @@ impl CookieStorage {
}))
}
}

fn reg_host<'a>(url: &'a str) -> String {
reg_suffix(url).to_string()
}
Expand Down

0 comments on commit 64b456f

Please sign in to comment.