Cookies are now expired immediately before each lookup

This commit is contained in:
Patrick Shaughnessy 2020-01-24 17:51:34 -05:00
parent 12693b51f5
commit 6d31827464
7 changed files with 16 additions and 70 deletions

View file

@ -10,6 +10,7 @@ use net_traits::pub_domains::reg_suffix;
use net_traits::CookieSource;
use servo_url::ServoUrl;
use std::cmp::Ordering;
use std::collections::hash_map::Entry;
use std::collections::HashMap;
use time::{self, Tm};
@ -144,6 +145,17 @@ impl CookieStorage {
}
}
pub fn remove_expired_cookies_for_url(&mut self, url: &ServoUrl) {
let domain = reg_host(url.host_str().unwrap_or(""));
if let Entry::Occupied(mut entry) = self.cookies_map.entry(domain) {
let cookies = entry.get_mut();
cookies.retain(|c| !is_cookie_expired(&c));
if cookies.len() == 0 {
entry.remove_entry();
}
}
}
// http://tools.ietf.org/html/rfc6265#section-5.4
pub fn cookies_for_url(&mut self, url: &ServoUrl, source: CookieSource) -> Option<String> {
let filterer = |c: &&mut Cookie| -> bool {

View file

@ -248,6 +248,7 @@ pub fn set_request_cookies(
cookie_jar: &RwLock<CookieStorage>,
) {
let mut cookie_jar = cookie_jar.write().unwrap();
cookie_jar.remove_expired_cookies_for_url(url);
if let Some(cookie_list) = cookie_jar.cookies_for_url(url, CookieSource::HTTP) {
headers.insert(
header::COOKIE,

View file

@ -291,6 +291,7 @@ impl ResourceChannelManager {
},
CoreResourceMsg::GetCookiesForUrl(url, consumer, source) => {
let mut cookie_jar = http_state.cookie_jar.write().unwrap();
cookie_jar.remove_expired_cookies_for_url(&url);
consumer
.send(cookie_jar.cookies_for_url(&url, source))
.unwrap();
@ -300,6 +301,7 @@ impl ResourceChannelManager {
},
CoreResourceMsg::GetCookiesDataForUrl(url, consumer, source) => {
let mut cookie_jar = http_state.cookie_jar.write().unwrap();
cookie_jar.remove_expired_cookies_for_url(&url);
let cookies = cookie_jar
.cookies_data_for_url(&url, source)
.map(Serde)

View file

@ -70,6 +70,7 @@ impl<'a> Handler for Client<'a> {
}
let mut cookie_jar = self.http_state.cookie_jar.write().unwrap();
cookie_jar.remove_expired_cookies_for_url(self.resource_url);
if let Some(cookie_list) = cookie_jar.cookies_for_url(self.resource_url, CookieSource::HTTP)
{
req.headers_mut()

View file

@ -1,15 +0,0 @@
[cors-cookies-redirect.any.worker.html]
[Untitled]
expected: FAIL
[cors-cookies-redirect]
expected: FAIL
[cors-cookies-redirect.any.html]
[Untitled]
expected: FAIL
[cors-cookies-redirect]
expected: FAIL

View file

@ -1,26 +0,0 @@
[cors-cookies.any.html]
type: testharness
[Include mode: local cookies are not sent with remote request]
expected: FAIL
[Include mode: remote cookies are not sent with local request]
expected: FAIL
[cors-cookies.any.worker.html]
type: testharness
[Include mode: local cookies are not sent with remote request]
expected: FAIL
[Include mode: remote cookies are not sent with local request]
expected: FAIL
[Include mode: remote cookies are not sent with local request]
expected: FAIL
[Include mode: local cookies are not sent with remote request]
expected: FAIL
[cors-cookies]
expected: FAIL

View file

@ -1,29 +0,0 @@
[cookies.any.html]
type: testharness
[Include mode: 2 cookies]
expected: FAIL
[Omit mode: no cookie is stored]
expected: FAIL
[Same-origin mode: 1 cookie]
expected: FAIL
[Same-origin mode: 2 cookies]
expected: FAIL
[cookies.any.worker.html]
type: testharness
[Include mode: 2 cookies]
expected: FAIL
[Omit mode: no cookie is stored]
expected: FAIL
[Same-origin mode: 1 cookie]
expected: FAIL
[Same-origin mode: 2 cookies]
expected: FAIL