mirror of
https://github.com/servo/servo.git
synced 2025-07-22 23:03:42 +01:00
dependencies: Upgrade cookie
and rename Servo's Cookie
to ServoCookie
(#32861)
This changes updates to the new version of the `cookie` crate in Servo which no longer uses the old `time@0.1` data types. This requires using a new version of `time` while we transition off of the old one. This is the first step in that process. In addition, the overloading of the `cookie::Cookie` name was causing a great deal of confusion, so I've renamed the Servo wrapper to `ServoCookie` like we do with `ServoUrl`. Signed-off-by: Martin Robinson <mrobinson@igalia.com>
This commit is contained in:
parent
8f377a0cb1
commit
b6f1e3b22d
16 changed files with 203 additions and 199 deletions
26
Cargo.lock
generated
26
Cargo.lock
generated
|
@ -981,18 +981,19 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "cookie"
|
||||
version = "0.12.0"
|
||||
version = "0.16.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "888604f00b3db336d2af898ec3c1d5d0ddf5e6d462220f2ededc33a87ac4bbd5"
|
||||
checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb"
|
||||
dependencies = [
|
||||
"time 0.1.45",
|
||||
"time 0.3.36",
|
||||
"version_check",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "cookie"
|
||||
version = "0.16.2"
|
||||
version = "0.18.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e859cd57d0710d9e06c381b550c06e76992472a8c6d527aecd2fc673dcc231fb"
|
||||
checksum = "4ddef33a339a91ea89fb53151bd0a4689cfce27055c291dfa69945475d22c747"
|
||||
dependencies = [
|
||||
"time 0.3.36",
|
||||
"version_check",
|
||||
|
@ -1276,6 +1277,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4"
|
||||
dependencies = [
|
||||
"powerfmt",
|
||||
"serde",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2903,7 +2905,7 @@ dependencies = [
|
|||
name = "hyper_serde"
|
||||
version = "0.13.2"
|
||||
dependencies = [
|
||||
"cookie 0.12.0",
|
||||
"cookie 0.18.1",
|
||||
"headers",
|
||||
"http",
|
||||
"hyper",
|
||||
|
@ -2912,6 +2914,7 @@ dependencies = [
|
|||
"serde_bytes",
|
||||
"serde_test",
|
||||
"time 0.1.45",
|
||||
"time 0.3.36",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -4135,7 +4138,7 @@ dependencies = [
|
|||
"bytes",
|
||||
"chrono",
|
||||
"content-security-policy",
|
||||
"cookie 0.12.0",
|
||||
"cookie 0.18.1",
|
||||
"crossbeam-channel",
|
||||
"data-url",
|
||||
"devtools_traits",
|
||||
|
@ -4172,6 +4175,7 @@ dependencies = [
|
|||
"servo_url",
|
||||
"sha2",
|
||||
"time 0.1.45",
|
||||
"time 0.3.36",
|
||||
"tokio",
|
||||
"tokio-rustls",
|
||||
"tokio-stream",
|
||||
|
@ -4190,7 +4194,7 @@ version = "0.0.1"
|
|||
dependencies = [
|
||||
"base",
|
||||
"content-security-policy",
|
||||
"cookie 0.12.0",
|
||||
"cookie 0.18.1",
|
||||
"embedder_traits",
|
||||
"headers",
|
||||
"http",
|
||||
|
@ -5196,7 +5200,7 @@ dependencies = [
|
|||
"canvas_traits",
|
||||
"chrono",
|
||||
"content-security-policy",
|
||||
"cookie 0.12.0",
|
||||
"cookie 0.18.1",
|
||||
"crossbeam-channel",
|
||||
"cssparser",
|
||||
"data-url",
|
||||
|
@ -5334,7 +5338,7 @@ dependencies = [
|
|||
"bitflags 2.6.0",
|
||||
"bluetooth_traits",
|
||||
"canvas_traits",
|
||||
"cookie 0.12.0",
|
||||
"cookie 0.18.1",
|
||||
"crossbeam-channel",
|
||||
"devtools_traits",
|
||||
"embedder_traits",
|
||||
|
@ -7228,7 +7232,7 @@ dependencies = [
|
|||
"base",
|
||||
"base64",
|
||||
"compositing_traits",
|
||||
"cookie 0.12.0",
|
||||
"cookie 0.18.1",
|
||||
"crossbeam-channel",
|
||||
"euclid",
|
||||
"http",
|
||||
|
|
|
@ -34,7 +34,7 @@ cfg-if = "1.0.0"
|
|||
chrono = "0.4"
|
||||
compositing_traits = { path = "components/shared/compositing" }
|
||||
content-security-policy = { version = "0.5", features = ["serde"] }
|
||||
cookie = "0.12"
|
||||
cookie = { package = "cookie", version = "0.18" }
|
||||
crossbeam-channel = "0.5"
|
||||
cssparser = { version = "0.34", features = ["serde"] }
|
||||
darling = { version = "0.20", default-features = false }
|
||||
|
@ -121,6 +121,7 @@ syn = { version = "2", default-features = false, features = ["clone-impls", "der
|
|||
synstructure = "0.13"
|
||||
thin-vec = "0.2.13"
|
||||
time = "0.1.41"
|
||||
time_03 = { package = "time", version = "0.3", features = ["serde"] }
|
||||
to_shmem = { git = "https://github.com/servo/stylo", branch = "2024-07-16" }
|
||||
tokio = "1"
|
||||
tokio-rustls = "0.24"
|
||||
|
|
|
@ -24,6 +24,7 @@ mime = { workspace = true }
|
|||
serde = { workspace = true }
|
||||
serde_bytes = { workspace = true }
|
||||
time = { workspace = true }
|
||||
time_03 = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
serde_test = "1.0"
|
||||
|
|
|
@ -8,14 +8,14 @@
|
|||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
use cookie::Cookie;
|
||||
use cookie::{Cookie, CookieBuilder};
|
||||
use headers::ContentType;
|
||||
use http::header::{self, HeaderMap, HeaderValue};
|
||||
use http::StatusCode;
|
||||
use hyper::{Method, Uri};
|
||||
use hyper_serde::{De, Ser};
|
||||
use serde_test::{assert_de_tokens, assert_ser_tokens, Token};
|
||||
use time::Duration;
|
||||
use time_03::Duration;
|
||||
|
||||
#[test]
|
||||
fn test_content_type() {
|
||||
|
@ -31,13 +31,13 @@ fn test_cookie() {
|
|||
// Unfortunately we have to do the to_string().parse() dance here to avoid the object being a
|
||||
// string with a bunch of indices in it which apparently is different from the exact same
|
||||
// cookie but parsed as a bunch of strings.
|
||||
let cookie: Cookie = Cookie::build("Hello", "World!")
|
||||
let cookie: Cookie = CookieBuilder::new("Hello", "World!")
|
||||
.max_age(Duration::seconds(42))
|
||||
.domain("servo.org")
|
||||
.path("/")
|
||||
.secure(true)
|
||||
.http_only(false)
|
||||
.finish()
|
||||
.build()
|
||||
.to_string()
|
||||
.parse()
|
||||
.unwrap();
|
||||
|
|
|
@ -21,7 +21,7 @@ base64 = { workspace = true }
|
|||
brotli = "3"
|
||||
bytes = "1"
|
||||
content-security-policy = { workspace = true }
|
||||
cookie_rs = { package = "cookie", version = "0.12" }
|
||||
cookie = { workspace = true }
|
||||
crossbeam-channel = { workspace = true }
|
||||
data-url = { workspace = true }
|
||||
devtools_traits = { workspace = true }
|
||||
|
@ -58,6 +58,7 @@ servo_config = { path = "../config" }
|
|||
servo_url = { path = "../url" }
|
||||
sha2 = "0.10"
|
||||
time = { workspace = true }
|
||||
time_03 = { workspace = true }
|
||||
chrono = { workspace = true }
|
||||
tokio = { workspace = true, features = ["sync", "macros", "rt-multi-thread"] }
|
||||
tokio-rustls = { workspace = true }
|
||||
|
|
|
@ -8,23 +8,24 @@
|
|||
use std::borrow::ToOwned;
|
||||
use std::net::{Ipv4Addr, Ipv6Addr};
|
||||
|
||||
use hyper_serde::Serde;
|
||||
use cookie::Cookie;
|
||||
use net_traits::pub_domains::is_pub_domain;
|
||||
use net_traits::CookieSource;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use servo_url::ServoUrl;
|
||||
use time::{at, now, Duration, Tm};
|
||||
use time::{now, Tm};
|
||||
use time_03::OffsetDateTime;
|
||||
|
||||
/// 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, Deserialize, Serialize)]
|
||||
pub struct Cookie {
|
||||
pub struct ServoCookie {
|
||||
#[serde(
|
||||
deserialize_with = "hyper_serde::deserialize",
|
||||
serialize_with = "hyper_serde::serialize"
|
||||
)]
|
||||
pub cookie: cookie_rs::Cookie<'static>,
|
||||
pub cookie: Cookie<'static>,
|
||||
pub host_only: bool,
|
||||
pub persistent: bool,
|
||||
#[serde(
|
||||
|
@ -37,36 +38,31 @@ pub struct Cookie {
|
|||
serialize_with = "hyper_serde::serialize"
|
||||
)]
|
||||
pub last_access: Tm,
|
||||
pub expiry_time: Option<Serde<Tm>>,
|
||||
pub expiry_time: Option<OffsetDateTime>,
|
||||
}
|
||||
|
||||
impl Cookie {
|
||||
impl ServoCookie {
|
||||
pub fn from_cookie_string(
|
||||
cookie_str: String,
|
||||
request: &ServoUrl,
|
||||
source: CookieSource,
|
||||
) -> Option<Cookie> {
|
||||
cookie_rs::Cookie::parse(cookie_str)
|
||||
) -> Option<ServoCookie> {
|
||||
Cookie::parse(cookie_str)
|
||||
.ok()
|
||||
.map(|cookie| Cookie::new_wrapped(cookie, request, source))
|
||||
.map(|cookie| ServoCookie::new_wrapped(cookie, request, source))
|
||||
.unwrap_or(None)
|
||||
}
|
||||
|
||||
/// <http://tools.ietf.org/html/rfc6265#section-5.3>
|
||||
pub fn new_wrapped(
|
||||
mut cookie: cookie_rs::Cookie<'static>,
|
||||
mut cookie: Cookie<'static>,
|
||||
request: &ServoUrl,
|
||||
source: CookieSource,
|
||||
) -> Option<Cookie> {
|
||||
) -> Option<ServoCookie> {
|
||||
// Step 3
|
||||
let (persistent, expiry_time) = match (cookie.max_age(), cookie.expires()) {
|
||||
(Some(max_age), _) => (
|
||||
true,
|
||||
Some(at(
|
||||
now().to_timespec() + Duration::seconds(max_age.num_seconds())
|
||||
)),
|
||||
),
|
||||
(_, Some(expires)) => (true, Some(expires)),
|
||||
let (persistent, expiry_time) = match (cookie.max_age(), cookie.expires_datetime()) {
|
||||
(Some(max_age), _) => (true, Some(time_03::OffsetDateTime::now_utc() + max_age)),
|
||||
(_, Some(date_time)) => (true, Some(date_time)),
|
||||
_ => (false, None),
|
||||
};
|
||||
|
||||
|
@ -86,7 +82,7 @@ impl Cookie {
|
|||
|
||||
// Step 6
|
||||
let host_only = if !domain.is_empty() {
|
||||
if !Cookie::domain_match(&url_host, &domain) {
|
||||
if !ServoCookie::domain_match(&url_host, &domain) {
|
||||
return None;
|
||||
} else {
|
||||
cookie.set_domain(domain);
|
||||
|
@ -107,7 +103,7 @@ impl Cookie {
|
|||
})
|
||||
.to_owned();
|
||||
if !path.starts_with('/') {
|
||||
path = Cookie::default_path(request.path()).to_string();
|
||||
path = ServoCookie::default_path(request.path()).to_string();
|
||||
}
|
||||
cookie.set_path(path);
|
||||
|
||||
|
@ -131,13 +127,13 @@ impl Cookie {
|
|||
return None;
|
||||
}
|
||||
|
||||
Some(Cookie {
|
||||
Some(ServoCookie {
|
||||
cookie,
|
||||
host_only,
|
||||
persistent,
|
||||
creation_time: now(),
|
||||
last_access: now(),
|
||||
expiry_time: expiry_time.map(Serde),
|
||||
expiry_time,
|
||||
})
|
||||
}
|
||||
|
||||
|
@ -145,8 +141,8 @@ impl Cookie {
|
|||
self.last_access = now();
|
||||
}
|
||||
|
||||
pub fn set_expiry_time_negative(&mut self) {
|
||||
self.expiry_time = Some(Serde(now() - Duration::seconds(1)));
|
||||
pub fn set_expiry_time_in_past(&mut self) {
|
||||
self.expiry_time = Some(time_03::OffsetDateTime::UNIX_EPOCH);
|
||||
}
|
||||
|
||||
// http://tools.ietf.org/html/rfc6265#section-5.1.4
|
||||
|
@ -206,13 +202,13 @@ impl Cookie {
|
|||
return false;
|
||||
}
|
||||
} else if let (Some(domain), Some(cookie_domain)) = (domain, &self.cookie.domain()) {
|
||||
if !Cookie::domain_match(domain, cookie_domain) {
|
||||
if !ServoCookie::domain_match(domain, cookie_domain) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if let Some(cookie_path) = self.cookie.path() {
|
||||
if !Cookie::path_match(url.path(), cookie_path) {
|
||||
if !ServoCookie::path_match(url.path(), cookie_path) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,14 +14,15 @@ use net_traits::pub_domains::reg_suffix;
|
|||
use net_traits::CookieSource;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use servo_url::ServoUrl;
|
||||
use time::{self, Tm};
|
||||
use time::Tm;
|
||||
use time_03::OffsetDateTime;
|
||||
|
||||
use crate::cookie::Cookie;
|
||||
use crate::cookie::ServoCookie;
|
||||
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct CookieStorage {
|
||||
version: u32,
|
||||
cookies_map: HashMap<String, Vec<Cookie>>,
|
||||
cookies_map: HashMap<String, Vec<ServoCookie>>,
|
||||
max_per_host: usize,
|
||||
}
|
||||
|
||||
|
@ -43,10 +44,10 @@ impl CookieStorage {
|
|||
// http://tools.ietf.org/html/rfc6265#section-5.3
|
||||
pub fn remove(
|
||||
&mut self,
|
||||
cookie: &Cookie,
|
||||
cookie: &ServoCookie,
|
||||
url: &ServoUrl,
|
||||
source: CookieSource,
|
||||
) -> Result<Option<Cookie>, RemoveCookieError> {
|
||||
) -> Result<Option<ServoCookie>, RemoveCookieError> {
|
||||
let domain = reg_host(cookie.cookie.domain().as_ref().unwrap_or(&""));
|
||||
let cookies = self.cookies_map.entry(domain).or_default();
|
||||
|
||||
|
@ -61,9 +62,9 @@ impl CookieStorage {
|
|||
|
||||
c.cookie.name() == cookie.cookie.name() &&
|
||||
c.cookie.secure().unwrap_or(false) &&
|
||||
(Cookie::domain_match(new_domain, existing_domain) ||
|
||||
Cookie::domain_match(existing_domain, new_domain)) &&
|
||||
Cookie::path_match(new_path, existing_path)
|
||||
(ServoCookie::domain_match(new_domain, existing_domain) ||
|
||||
ServoCookie::domain_match(existing_domain, new_domain)) &&
|
||||
ServoCookie::path_match(new_path, existing_path)
|
||||
});
|
||||
|
||||
if any_overlapping {
|
||||
|
@ -98,12 +99,12 @@ impl CookieStorage {
|
|||
let domain = reg_host(url.host_str().unwrap_or(""));
|
||||
let cookies = self.cookies_map.entry(domain).or_default();
|
||||
for cookie in cookies.iter_mut() {
|
||||
cookie.set_expiry_time_negative();
|
||||
cookie.set_expiry_time_in_past();
|
||||
}
|
||||
}
|
||||
|
||||
// http://tools.ietf.org/html/rfc6265#section-5.3
|
||||
pub fn push(&mut self, mut cookie: Cookie, url: &ServoUrl, source: CookieSource) {
|
||||
pub fn push(&mut self, mut cookie: ServoCookie, url: &ServoUrl, source: CookieSource) {
|
||||
// https://www.ietf.org/id/draft-ietf-httpbis-cookie-alone-01.txt Step 1
|
||||
if cookie.cookie.secure().unwrap_or(false) && !url.is_secure_scheme() {
|
||||
return;
|
||||
|
@ -140,7 +141,7 @@ impl CookieStorage {
|
|||
cookies.push(cookie);
|
||||
}
|
||||
|
||||
pub fn cookie_comparator(a: &Cookie, b: &Cookie) -> Ordering {
|
||||
pub fn cookie_comparator(a: &ServoCookie, b: &ServoCookie) -> Ordering {
|
||||
let a_path_len = a.cookie.path().as_ref().map_or(0, |p| p.len());
|
||||
let b_path_len = b.cookie.path().as_ref().map_or(0, |p| p.len());
|
||||
match a_path_len.cmp(&b_path_len) {
|
||||
|
@ -168,7 +169,7 @@ impl CookieStorage {
|
|||
|
||||
// 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 {
|
||||
let filterer = |c: &&mut ServoCookie| -> bool {
|
||||
debug!(
|
||||
" === SENT COOKIE : {} {} {:?} {:?}",
|
||||
c.cookie.name(),
|
||||
|
@ -187,10 +188,10 @@ impl CookieStorage {
|
|||
let domain = reg_host(url.host_str().unwrap_or(""));
|
||||
let cookies = self.cookies_map.entry(domain).or_default();
|
||||
|
||||
let mut url_cookies: Vec<&mut Cookie> = cookies.iter_mut().filter(filterer).collect();
|
||||
let mut url_cookies: Vec<&mut ServoCookie> = cookies.iter_mut().filter(filterer).collect();
|
||||
url_cookies.sort_by(|a, b| CookieStorage::cookie_comparator(a, b));
|
||||
|
||||
let reducer = |acc: String, c: &mut &mut Cookie| -> String {
|
||||
let reducer = |acc: String, c: &mut &mut ServoCookie| -> String {
|
||||
// Step 3
|
||||
c.touch();
|
||||
|
||||
|
@ -215,7 +216,7 @@ impl CookieStorage {
|
|||
&'a mut self,
|
||||
url: &'a ServoUrl,
|
||||
source: CookieSource,
|
||||
) -> impl Iterator<Item = cookie_rs::Cookie<'static>> + 'a {
|
||||
) -> impl Iterator<Item = cookie::Cookie<'static>> + 'a {
|
||||
let domain = reg_host(url.host_str().unwrap_or(""));
|
||||
let cookies = self.cookies_map.entry(domain).or_default();
|
||||
|
||||
|
@ -233,14 +234,11 @@ fn reg_host(url: &str) -> String {
|
|||
reg_suffix(url).to_lowercase()
|
||||
}
|
||||
|
||||
fn is_cookie_expired(cookie: &Cookie) -> bool {
|
||||
match cookie.expiry_time {
|
||||
Some(ref t) => t.to_timespec() <= time::get_time(),
|
||||
None => false,
|
||||
}
|
||||
fn is_cookie_expired(cookie: &ServoCookie) -> bool {
|
||||
matches!(cookie.expiry_time, Some(date_time) if date_time <= OffsetDateTime::now_utc())
|
||||
}
|
||||
|
||||
fn evict_one_cookie(is_secure_cookie: bool, cookies: &mut Vec<Cookie>) -> bool {
|
||||
fn evict_one_cookie(is_secure_cookie: bool, cookies: &mut Vec<ServoCookie>) -> bool {
|
||||
// Remove non-secure cookie with oldest access time
|
||||
let oldest_accessed: Option<(usize, Tm)> = get_oldest_accessed(false, cookies);
|
||||
|
||||
|
@ -259,7 +257,7 @@ fn evict_one_cookie(is_secure_cookie: bool, cookies: &mut Vec<Cookie>) -> bool {
|
|||
true
|
||||
}
|
||||
|
||||
fn get_oldest_accessed(is_secure_cookie: bool, cookies: &mut [Cookie]) -> Option<(usize, Tm)> {
|
||||
fn get_oldest_accessed(is_secure_cookie: bool, cookies: &mut [ServoCookie]) -> Option<(usize, Tm)> {
|
||||
let mut oldest_accessed: Option<(usize, Tm)> = None;
|
||||
for (i, c) in cookies.iter().enumerate() {
|
||||
if (c.cookie.secure().unwrap_or(false) == is_secure_cookie) &&
|
||||
|
|
|
@ -60,7 +60,7 @@ use crate::connector::{
|
|||
create_http_client, create_tls_config, CACertificates, CertificateErrorOverrideManager,
|
||||
Connector,
|
||||
};
|
||||
use crate::cookie;
|
||||
use crate::cookie::ServoCookie;
|
||||
use crate::cookie_storage::CookieStorage;
|
||||
use crate::decoder::Decoder;
|
||||
use crate::fetch::cors_cache::CorsCache;
|
||||
|
@ -328,7 +328,7 @@ fn set_cookie_for_url(cookie_jar: &RwLock<CookieStorage>, request: &ServoUrl, co
|
|||
let mut cookie_jar = cookie_jar.write().unwrap();
|
||||
let source = CookieSource::HTTP;
|
||||
|
||||
if let Some(cookie) = cookie::Cookie::from_cookie_string(cookie_val.into(), request, source) {
|
||||
if let Some(cookie) = ServoCookie::from_cookie_string(cookie_val.into(), request, source) {
|
||||
cookie_jar.push(cookie, request, source);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,6 +14,7 @@ use std::sync::{Arc, Mutex, RwLock};
|
|||
use std::thread;
|
||||
use std::time::Duration;
|
||||
|
||||
use cookie::Cookie;
|
||||
use crossbeam_channel::Sender;
|
||||
use devtools_traits::DevtoolsControlMsg;
|
||||
use embedder_traits::EmbedderProxy;
|
||||
|
@ -43,6 +44,7 @@ use crate::async_runtime::HANDLE;
|
|||
use crate::connector::{
|
||||
create_http_client, create_tls_config, CACertificates, CertificateErrorOverrideManager,
|
||||
};
|
||||
use crate::cookie::ServoCookie;
|
||||
use crate::cookie_storage::CookieStorage;
|
||||
use crate::fetch::cors_cache::CorsCache;
|
||||
use crate::fetch::methods::{fetch, CancellationListener, FetchContext};
|
||||
|
@ -51,7 +53,7 @@ use crate::hsts::HstsList;
|
|||
use crate::http_cache::HttpCache;
|
||||
use crate::http_loader::{http_redirect_fetch, HttpState};
|
||||
use crate::storage_thread::StorageThreadFactory;
|
||||
use crate::{cookie, websocket_loader};
|
||||
use crate::websocket_loader;
|
||||
|
||||
/// Load a file with CA certificate and produce a RootCertStore with the results.
|
||||
fn load_root_cert_store_from_file(file_path: String) -> io::Result<RootCertStore> {
|
||||
|
@ -315,7 +317,7 @@ impl ResourceChannelManager {
|
|||
.fetch(req_init, Some(res_init), sender, http_state, cancel_chan),
|
||||
CoreResourceMsg::SetCookieForUrl(request, cookie, source) => self
|
||||
.resource_manager
|
||||
.set_cookie_for_url(&request, cookie.into_inner(), source, http_state),
|
||||
.set_cookie_for_url(&request, cookie.into_inner().to_owned(), source, http_state),
|
||||
CoreResourceMsg::SetCookiesForUrl(request, cookies, source) => {
|
||||
for cookie in cookies {
|
||||
self.resource_manager.set_cookie_for_url(
|
||||
|
@ -637,11 +639,11 @@ impl CoreResourceManager {
|
|||
fn set_cookie_for_url(
|
||||
&mut self,
|
||||
request: &ServoUrl,
|
||||
cookie: cookie_rs::Cookie<'static>,
|
||||
cookie: Cookie<'static>,
|
||||
source: CookieSource,
|
||||
http_state: &Arc<HttpState>,
|
||||
) {
|
||||
if let Some(cookie) = cookie::Cookie::new_wrapped(cookie, request, source) {
|
||||
if let Some(cookie) = ServoCookie::new_wrapped(cookie, request, source) {
|
||||
let mut cookie_jar = http_state.cookie_jar.write().unwrap();
|
||||
cookie_jar.push(cookie, request, source)
|
||||
}
|
||||
|
|
|
@ -2,53 +2,53 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use net::cookie::Cookie;
|
||||
use net::cookie::ServoCookie;
|
||||
use net::cookie_storage::CookieStorage;
|
||||
use net_traits::CookieSource;
|
||||
use servo_url::ServoUrl;
|
||||
|
||||
#[test]
|
||||
fn test_domain_match() {
|
||||
assert!(Cookie::domain_match("foo.com", "foo.com"));
|
||||
assert!(Cookie::domain_match("bar.foo.com", "foo.com"));
|
||||
assert!(Cookie::domain_match("baz.bar.foo.com", "foo.com"));
|
||||
assert!(ServoCookie::domain_match("foo.com", "foo.com"));
|
||||
assert!(ServoCookie::domain_match("bar.foo.com", "foo.com"));
|
||||
assert!(ServoCookie::domain_match("baz.bar.foo.com", "foo.com"));
|
||||
|
||||
assert!(!Cookie::domain_match("bar.foo.com", "bar.com"));
|
||||
assert!(!Cookie::domain_match("bar.com", "baz.bar.com"));
|
||||
assert!(!Cookie::domain_match("foo.com", "bar.com"));
|
||||
assert!(!ServoCookie::domain_match("bar.foo.com", "bar.com"));
|
||||
assert!(!ServoCookie::domain_match("bar.com", "baz.bar.com"));
|
||||
assert!(!ServoCookie::domain_match("foo.com", "bar.com"));
|
||||
|
||||
assert!(!Cookie::domain_match("bar.com", "bbar.com"));
|
||||
assert!(Cookie::domain_match("235.132.2.3", "235.132.2.3"));
|
||||
assert!(!Cookie::domain_match("235.132.2.3", "1.1.1.1"));
|
||||
assert!(!Cookie::domain_match("235.132.2.3", ".2.3"));
|
||||
assert!(!ServoCookie::domain_match("bar.com", "bbar.com"));
|
||||
assert!(ServoCookie::domain_match("235.132.2.3", "235.132.2.3"));
|
||||
assert!(!ServoCookie::domain_match("235.132.2.3", "1.1.1.1"));
|
||||
assert!(!ServoCookie::domain_match("235.132.2.3", ".2.3"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_path_match() {
|
||||
assert!(Cookie::path_match("/", "/"));
|
||||
assert!(Cookie::path_match("/index.html", "/"));
|
||||
assert!(Cookie::path_match("/w/index.html", "/"));
|
||||
assert!(Cookie::path_match("/w/index.html", "/w/index.html"));
|
||||
assert!(Cookie::path_match("/w/index.html", "/w/"));
|
||||
assert!(Cookie::path_match("/w/index.html", "/w"));
|
||||
assert!(ServoCookie::path_match("/", "/"));
|
||||
assert!(ServoCookie::path_match("/index.html", "/"));
|
||||
assert!(ServoCookie::path_match("/w/index.html", "/"));
|
||||
assert!(ServoCookie::path_match("/w/index.html", "/w/index.html"));
|
||||
assert!(ServoCookie::path_match("/w/index.html", "/w/"));
|
||||
assert!(ServoCookie::path_match("/w/index.html", "/w"));
|
||||
|
||||
assert!(!Cookie::path_match("/", "/w/"));
|
||||
assert!(!Cookie::path_match("/a", "/w/"));
|
||||
assert!(!Cookie::path_match("/", "/w"));
|
||||
assert!(!Cookie::path_match("/w/index.html", "/w/index"));
|
||||
assert!(!Cookie::path_match("/windex.html", "/w/"));
|
||||
assert!(!Cookie::path_match("/windex.html", "/w"));
|
||||
assert!(!ServoCookie::path_match("/", "/w/"));
|
||||
assert!(!ServoCookie::path_match("/a", "/w/"));
|
||||
assert!(!ServoCookie::path_match("/", "/w"));
|
||||
assert!(!ServoCookie::path_match("/w/index.html", "/w/index"));
|
||||
assert!(!ServoCookie::path_match("/windex.html", "/w/"));
|
||||
assert!(!ServoCookie::path_match("/windex.html", "/w"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_default_path() {
|
||||
assert_eq!(&*Cookie::default_path("/foo/bar/baz/"), "/foo/bar/baz");
|
||||
assert_eq!(&*Cookie::default_path("/foo/bar/baz"), "/foo/bar");
|
||||
assert_eq!(&*Cookie::default_path("/foo/"), "/foo");
|
||||
assert_eq!(&*Cookie::default_path("/foo"), "/");
|
||||
assert_eq!(&*Cookie::default_path("/"), "/");
|
||||
assert_eq!(&*Cookie::default_path(""), "/");
|
||||
assert_eq!(&*Cookie::default_path("foo"), "/");
|
||||
assert_eq!(&*ServoCookie::default_path("/foo/bar/baz/"), "/foo/bar/baz");
|
||||
assert_eq!(&*ServoCookie::default_path("/foo/bar/baz"), "/foo/bar");
|
||||
assert_eq!(&*ServoCookie::default_path("/foo/"), "/foo");
|
||||
assert_eq!(&*ServoCookie::default_path("/foo"), "/");
|
||||
assert_eq!(&*ServoCookie::default_path("/"), "/");
|
||||
assert_eq!(&*ServoCookie::default_path(""), "/");
|
||||
assert_eq!(&*ServoCookie::default_path("foo"), "/");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
@ -59,33 +59,33 @@ fn fn_cookie_constructor() {
|
|||
|
||||
let gov_url = &ServoUrl::parse("http://gov.ac/foo").unwrap();
|
||||
// cookie name/value test
|
||||
assert!(cookie_rs::Cookie::parse(" baz ").is_err());
|
||||
assert!(cookie_rs::Cookie::parse(" = bar ").is_err());
|
||||
assert!(cookie_rs::Cookie::parse(" baz = ").is_ok());
|
||||
assert!(cookie::Cookie::parse(" baz ").is_err());
|
||||
assert!(cookie::Cookie::parse(" = bar ").is_err());
|
||||
assert!(cookie::Cookie::parse(" baz = ").is_ok());
|
||||
|
||||
// cookie domains test
|
||||
let cookie = cookie_rs::Cookie::parse(" baz = bar; Domain = ").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie.clone(), url, CookieSource::HTTP).is_some());
|
||||
let cookie = Cookie::new_wrapped(cookie, url, CookieSource::HTTP).unwrap();
|
||||
let cookie = cookie::Cookie::parse(" baz = bar; Domain = ").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie.clone(), url, CookieSource::HTTP).is_some());
|
||||
let cookie = ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).unwrap();
|
||||
assert_eq!(&**cookie.cookie.domain().as_ref().unwrap(), "example.com");
|
||||
|
||||
// cookie public domains test
|
||||
let cookie = cookie_rs::Cookie::parse(" baz = bar; Domain = gov.ac").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie.clone(), url, CookieSource::HTTP).is_none());
|
||||
assert!(Cookie::new_wrapped(cookie, gov_url, CookieSource::HTTP).is_some());
|
||||
let cookie = cookie::Cookie::parse(" baz = bar; Domain = gov.ac").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie.clone(), url, CookieSource::HTTP).is_none());
|
||||
assert!(ServoCookie::new_wrapped(cookie, gov_url, CookieSource::HTTP).is_some());
|
||||
|
||||
// cookie domain matching test
|
||||
let cookie = cookie_rs::Cookie::parse(" baz = bar ; Secure; Domain = bazample.com").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
let cookie = cookie::Cookie::parse(" baz = bar ; Secure; Domain = bazample.com").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
|
||||
let cookie = cookie_rs::Cookie::parse(" baz = bar ; Secure; Path = /foo/bar/").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::HTTP).is_some());
|
||||
let cookie = cookie::Cookie::parse(" baz = bar ; Secure; Path = /foo/bar/").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).is_some());
|
||||
|
||||
let cookie = cookie_rs::Cookie::parse(" baz = bar ; HttpOnly").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::NonHTTP).is_none());
|
||||
let cookie = cookie::Cookie::parse(" baz = bar ; HttpOnly").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::NonHTTP).is_none());
|
||||
|
||||
let cookie = cookie_rs::Cookie::parse(" baz = bar ; Secure; Path = /foo/bar/").unwrap();
|
||||
let cookie = Cookie::new_wrapped(cookie, url, CookieSource::HTTP).unwrap();
|
||||
let cookie = cookie::Cookie::parse(" baz = bar ; Secure; Path = /foo/bar/").unwrap();
|
||||
let cookie = ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).unwrap();
|
||||
assert_eq!(cookie.cookie.value(), "bar");
|
||||
assert_eq!(cookie.cookie.name(), "baz");
|
||||
assert!(cookie.cookie.secure().unwrap_or(false));
|
||||
|
@ -94,77 +94,75 @@ fn fn_cookie_constructor() {
|
|||
assert!(cookie.host_only);
|
||||
|
||||
let u = &ServoUrl::parse("http://example.com/foobar").unwrap();
|
||||
let cookie = cookie_rs::Cookie::parse("foobar=value;path=/").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, u, CookieSource::HTTP).is_some());
|
||||
let cookie = cookie::Cookie::parse("foobar=value;path=/").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, u, CookieSource::HTTP).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cookie_secure_prefix() {
|
||||
let url = &ServoUrl::parse("https://example.com").unwrap();
|
||||
let cookie = cookie_rs::Cookie::parse("__Secure-SID=12345").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
let cookie = cookie::Cookie::parse("__Secure-SID=12345").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
|
||||
let url = &ServoUrl::parse("http://example.com").unwrap();
|
||||
let cookie = cookie_rs::Cookie::parse("__Secure-SID=12345; Secure").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
let cookie = cookie::Cookie::parse("__Secure-SID=12345; Secure").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
|
||||
let url = &ServoUrl::parse("https://example.com").unwrap();
|
||||
let cookie = cookie_rs::Cookie::parse("__Secure-SID=12345; Secure").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::HTTP).is_some());
|
||||
let cookie = cookie::Cookie::parse("__Secure-SID=12345; Secure").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).is_some());
|
||||
|
||||
let url = &ServoUrl::parse("https://example.com").unwrap();
|
||||
let cookie = cookie_rs::Cookie::parse("__Secure-SID=12345; Domain=example.com").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
let cookie = cookie::Cookie::parse("__Secure-SID=12345; Domain=example.com").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
|
||||
let url = &ServoUrl::parse("http://example.com").unwrap();
|
||||
let cookie =
|
||||
cookie_rs::Cookie::parse("__Secure-SID=12345; Secure; Domain=example.com").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
let cookie = cookie::Cookie::parse("__Secure-SID=12345; Secure; Domain=example.com").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
|
||||
let url = &ServoUrl::parse("https://example.com").unwrap();
|
||||
let cookie =
|
||||
cookie_rs::Cookie::parse("__Secure-SID=12345; Secure; Domain=example.com").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::HTTP).is_some());
|
||||
let cookie = cookie::Cookie::parse("__Secure-SID=12345; Secure; Domain=example.com").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_cookie_host_prefix() {
|
||||
let url = &ServoUrl::parse("https://example.com").unwrap();
|
||||
let cookie = cookie_rs::Cookie::parse("__Host-SID=12345").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
let cookie = cookie::Cookie::parse("__Host-SID=12345").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
|
||||
let url = &ServoUrl::parse("http://example.com").unwrap();
|
||||
let cookie = cookie_rs::Cookie::parse("__Host-SID=12345; Secure").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
let cookie = cookie::Cookie::parse("__Host-SID=12345; Secure").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
|
||||
let url = &ServoUrl::parse("https://example.com").unwrap();
|
||||
let cookie = cookie_rs::Cookie::parse("__Host-SID=12345; Secure").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
let cookie = cookie::Cookie::parse("__Host-SID=12345; Secure").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
|
||||
let url = &ServoUrl::parse("https://example.com").unwrap();
|
||||
let cookie = cookie_rs::Cookie::parse("__Host-SID=12345; Domain=example.com").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
let cookie = cookie::Cookie::parse("__Host-SID=12345; Domain=example.com").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
|
||||
let url = &ServoUrl::parse("https://example.com").unwrap();
|
||||
let cookie = cookie_rs::Cookie::parse("__Host-SID=12345; Domain=example.com; Path=/").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
let cookie = cookie::Cookie::parse("__Host-SID=12345; Domain=example.com; Path=/").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
|
||||
let url = &ServoUrl::parse("http://example.com").unwrap();
|
||||
let cookie = cookie_rs::Cookie::parse("__Host-SID=12345; Secure; Domain=example.com").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
let cookie = cookie::Cookie::parse("__Host-SID=12345; Secure; Domain=example.com").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
|
||||
let url = &ServoUrl::parse("https://example.com").unwrap();
|
||||
let cookie = cookie_rs::Cookie::parse("__Host-SID=12345; Secure; Domain=example.com").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
let cookie = cookie::Cookie::parse("__Host-SID=12345; Secure; Domain=example.com").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
|
||||
let url = &ServoUrl::parse("https://example.com").unwrap();
|
||||
let cookie =
|
||||
cookie_rs::Cookie::parse("__Host-SID=12345; Secure; Domain=example.com; Path=/").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
cookie::Cookie::parse("__Host-SID=12345; Secure; Domain=example.com; Path=/").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).is_none());
|
||||
|
||||
let url = &ServoUrl::parse("https://example.com").unwrap();
|
||||
let cookie = cookie_rs::Cookie::parse("__Host-SID=12345; Secure; Path=/").unwrap();
|
||||
assert!(Cookie::new_wrapped(cookie, url, CookieSource::HTTP).is_some());
|
||||
let cookie = cookie::Cookie::parse("__Host-SID=12345; Secure; Path=/").unwrap();
|
||||
assert!(ServoCookie::new_wrapped(cookie, url, CookieSource::HTTP).is_some());
|
||||
}
|
||||
|
||||
#[cfg(target_os = "windows")]
|
||||
|
@ -185,12 +183,12 @@ fn test_sort_order() {
|
|||
use std::cmp::Ordering;
|
||||
|
||||
let url = &ServoUrl::parse("http://example.com/foo").unwrap();
|
||||
let a_wrapped = cookie_rs::Cookie::parse("baz=bar; Path=/foo/bar/").unwrap();
|
||||
let a = Cookie::new_wrapped(a_wrapped.clone(), url, CookieSource::HTTP).unwrap();
|
||||
let a_wrapped = cookie::Cookie::parse("baz=bar; Path=/foo/bar/").unwrap();
|
||||
let a = ServoCookie::new_wrapped(a_wrapped.clone(), url, CookieSource::HTTP).unwrap();
|
||||
delay_to_ensure_different_timestamp();
|
||||
let a_prime = Cookie::new_wrapped(a_wrapped, url, CookieSource::HTTP).unwrap();
|
||||
let b = cookie_rs::Cookie::parse("baz=bar;Path=/foo/bar/baz/").unwrap();
|
||||
let b = Cookie::new_wrapped(b, url, CookieSource::HTTP).unwrap();
|
||||
let a_prime = ServoCookie::new_wrapped(a_wrapped, url, CookieSource::HTTP).unwrap();
|
||||
let b = cookie::Cookie::parse("baz=bar;Path=/foo/bar/baz/").unwrap();
|
||||
let b = ServoCookie::new_wrapped(b, url, CookieSource::HTTP).unwrap();
|
||||
|
||||
assert!(b.cookie.path().as_ref().unwrap().len() > a.cookie.path().as_ref().unwrap().len());
|
||||
assert_eq!(CookieStorage::cookie_comparator(&a, &b), Ordering::Greater);
|
||||
|
@ -208,8 +206,8 @@ fn test_sort_order() {
|
|||
|
||||
fn add_cookie_to_storage(storage: &mut CookieStorage, url: &ServoUrl, cookie_str: &str) {
|
||||
let source = CookieSource::HTTP;
|
||||
let cookie = cookie_rs::Cookie::parse(cookie_str.to_owned()).unwrap();
|
||||
let cookie = Cookie::new_wrapped(cookie, url, source).unwrap();
|
||||
let cookie = cookie::Cookie::parse(cookie_str.to_owned()).unwrap();
|
||||
let cookie = ServoCookie::new_wrapped(cookie, url, source).unwrap();
|
||||
storage.push(cookie, url, source);
|
||||
}
|
||||
|
||||
|
@ -220,13 +218,13 @@ fn test_insecure_cookies_cannot_evict_secure_cookie() {
|
|||
let source = CookieSource::HTTP;
|
||||
let mut cookies = Vec::new();
|
||||
|
||||
cookies.push(cookie_rs::Cookie::parse("foo=bar; Secure; Domain=home.example.org").unwrap());
|
||||
cookies.push(cookie_rs::Cookie::parse("foo2=bar; Secure; Domain=.example.org").unwrap());
|
||||
cookies.push(cookie_rs::Cookie::parse("foo3=bar; Secure; Path=/foo").unwrap());
|
||||
cookies.push(cookie_rs::Cookie::parse("foo4=bar; Secure; Path=/foo/bar").unwrap());
|
||||
cookies.push(cookie::Cookie::parse("foo=bar; Secure; Domain=home.example.org").unwrap());
|
||||
cookies.push(cookie::Cookie::parse("foo2=bar; Secure; Domain=.example.org").unwrap());
|
||||
cookies.push(cookie::Cookie::parse("foo3=bar; Secure; Path=/foo").unwrap());
|
||||
cookies.push(cookie::Cookie::parse("foo4=bar; Secure; Path=/foo/bar").unwrap());
|
||||
|
||||
for bare_cookie in cookies {
|
||||
let cookie = Cookie::new_wrapped(bare_cookie, &secure_url, source).unwrap();
|
||||
let cookie = ServoCookie::new_wrapped(bare_cookie, &secure_url, source).unwrap();
|
||||
storage.push(cookie, &secure_url, source);
|
||||
}
|
||||
|
||||
|
@ -275,13 +273,13 @@ fn test_secure_cookies_eviction() {
|
|||
let source = CookieSource::HTTP;
|
||||
let mut cookies = Vec::new();
|
||||
|
||||
cookies.push(cookie_rs::Cookie::parse("foo=bar; Secure; Domain=home.example.org").unwrap());
|
||||
cookies.push(cookie_rs::Cookie::parse("foo2=bar; Secure; Domain=.example.org").unwrap());
|
||||
cookies.push(cookie_rs::Cookie::parse("foo3=bar; Secure; Path=/foo").unwrap());
|
||||
cookies.push(cookie_rs::Cookie::parse("foo4=bar; Secure; Path=/foo/bar").unwrap());
|
||||
cookies.push(cookie::Cookie::parse("foo=bar; Secure; Domain=home.example.org").unwrap());
|
||||
cookies.push(cookie::Cookie::parse("foo2=bar; Secure; Domain=.example.org").unwrap());
|
||||
cookies.push(cookie::Cookie::parse("foo3=bar; Secure; Path=/foo").unwrap());
|
||||
cookies.push(cookie::Cookie::parse("foo4=bar; Secure; Path=/foo/bar").unwrap());
|
||||
|
||||
for bare_cookie in cookies {
|
||||
let cookie = Cookie::new_wrapped(bare_cookie, &url, source).unwrap();
|
||||
let cookie = ServoCookie::new_wrapped(bare_cookie, &url, source).unwrap();
|
||||
storage.push(cookie, &url, source);
|
||||
}
|
||||
|
||||
|
@ -317,13 +315,13 @@ fn test_secure_cookies_eviction_non_http_source() {
|
|||
let source = CookieSource::NonHTTP;
|
||||
let mut cookies = Vec::new();
|
||||
|
||||
cookies.push(cookie_rs::Cookie::parse("foo=bar; Secure; Domain=home.example.org").unwrap());
|
||||
cookies.push(cookie_rs::Cookie::parse("foo2=bar; Secure; Domain=.example.org").unwrap());
|
||||
cookies.push(cookie_rs::Cookie::parse("foo3=bar; Secure; Path=/foo").unwrap());
|
||||
cookies.push(cookie_rs::Cookie::parse("foo4=bar; Secure; Path=/foo/bar").unwrap());
|
||||
cookies.push(cookie::Cookie::parse("foo=bar; Secure; Domain=home.example.org").unwrap());
|
||||
cookies.push(cookie::Cookie::parse("foo2=bar; Secure; Domain=.example.org").unwrap());
|
||||
cookies.push(cookie::Cookie::parse("foo3=bar; Secure; Path=/foo").unwrap());
|
||||
cookies.push(cookie::Cookie::parse("foo4=bar; Secure; Path=/foo/bar").unwrap());
|
||||
|
||||
for bare_cookie in cookies {
|
||||
let cookie = Cookie::new_wrapped(bare_cookie, &url, source).unwrap();
|
||||
let cookie = ServoCookie::new_wrapped(bare_cookie, &url, source).unwrap();
|
||||
storage.push(cookie, &url, source);
|
||||
}
|
||||
|
||||
|
@ -363,7 +361,7 @@ fn add_retrieve_cookies(
|
|||
|
||||
// Add all cookies to the store
|
||||
for str_cookie in set_cookies {
|
||||
let cookie = Cookie::from_cookie_string(str_cookie.to_owned(), &url, source).unwrap();
|
||||
let cookie = ServoCookie::from_cookie_string(str_cookie.to_owned(), &url, source).unwrap();
|
||||
storage.push(cookie, &url, source);
|
||||
}
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
|
||||
|
||||
use net::cookie::Cookie;
|
||||
use net::cookie::ServoCookie;
|
||||
use net::cookie_storage::CookieStorage;
|
||||
use net_traits::CookieSource;
|
||||
use servo_url::ServoUrl;
|
||||
|
@ -14,7 +14,8 @@ fn run(set_location: &str, set_cookies: &[&str], final_location: &str) -> String
|
|||
|
||||
// Add all cookies to the store
|
||||
for str_cookie in set_cookies {
|
||||
if let Some(cookie) = Cookie::from_cookie_string(str_cookie.to_owned().into(), &url, source)
|
||||
if let Some(cookie) =
|
||||
ServoCookie::from_cookie_string(str_cookie.to_owned().into(), &url, source)
|
||||
{
|
||||
storage.push(cookie, &url, source);
|
||||
}
|
||||
|
|
|
@ -12,7 +12,7 @@ use std::sync::{Arc, Mutex, RwLock};
|
|||
use std::time::Duration;
|
||||
|
||||
use base::id::TEST_PIPELINE_ID;
|
||||
use cookie_rs::Cookie as CookiePair;
|
||||
use cookie::Cookie as CookiePair;
|
||||
use crossbeam_channel::{unbounded, Receiver};
|
||||
use devtools_traits::{
|
||||
ChromeToDevtoolsControlMsg, DevtoolsControlMsg, HttpRequest as DevtoolsHttpRequest,
|
||||
|
@ -30,7 +30,7 @@ use http::{Method, StatusCode};
|
|||
use hyper::{Body, Request as HyperRequest, Response as HyperResponse};
|
||||
use ipc_channel::ipc;
|
||||
use ipc_channel::router::ROUTER;
|
||||
use net::cookie::Cookie;
|
||||
use net::cookie::ServoCookie;
|
||||
use net::cookie_storage::CookieStorage;
|
||||
use net::http_loader::determine_requests_referrer;
|
||||
use net::resource_thread::AuthCacheEntry;
|
||||
|
@ -648,7 +648,7 @@ fn test_load_sets_requests_cookies_header_for_url_by_getting_cookies_from_the_re
|
|||
|
||||
{
|
||||
let mut cookie_jar = context.state.cookie_jar.write().unwrap();
|
||||
let cookie = Cookie::new_wrapped(
|
||||
let cookie = ServoCookie::new_wrapped(
|
||||
CookiePair::new("mozillaIs".to_owned(), "theBest".to_owned()),
|
||||
&url,
|
||||
CookieSource::HTTP,
|
||||
|
@ -694,7 +694,7 @@ fn test_load_sends_cookie_if_nonhttp() {
|
|||
|
||||
{
|
||||
let mut cookie_jar = context.state.cookie_jar.write().unwrap();
|
||||
let cookie = Cookie::new_wrapped(
|
||||
let cookie = ServoCookie::new_wrapped(
|
||||
CookiePair::new("mozillaIs".to_owned(), "theBest".to_owned()),
|
||||
&url,
|
||||
CookieSource::NonHTTP,
|
||||
|
@ -1192,7 +1192,7 @@ fn test_redirect_from_x_to_y_provides_y_cookies_from_y() {
|
|||
let mut context = new_fetch_context(None, None, None);
|
||||
{
|
||||
let mut cookie_jar = context.state.cookie_jar.write().unwrap();
|
||||
let cookie_x = Cookie::new_wrapped(
|
||||
let cookie_x = ServoCookie::new_wrapped(
|
||||
CookiePair::new("mozillaIsNot".to_owned(), "dotOrg".to_owned()),
|
||||
&url_x,
|
||||
CookieSource::HTTP,
|
||||
|
@ -1201,7 +1201,7 @@ fn test_redirect_from_x_to_y_provides_y_cookies_from_y() {
|
|||
|
||||
cookie_jar.push(cookie_x, &url_x, CookieSource::HTTP);
|
||||
|
||||
let cookie_y = Cookie::new_wrapped(
|
||||
let cookie_y = ServoCookie::new_wrapped(
|
||||
CookiePair::new("mozillaIs".to_owned(), "theBest".to_owned()),
|
||||
&url_y,
|
||||
CookieSource::HTTP,
|
||||
|
|
|
@ -39,7 +39,7 @@ use url::Url;
|
|||
|
||||
use crate::async_runtime::HANDLE;
|
||||
use crate::connector::{create_tls_config, CACertificates, TlsConfig};
|
||||
use crate::cookie::Cookie;
|
||||
use crate::cookie::ServoCookie;
|
||||
use crate::fetch::methods::should_be_blocked_due_to_bad_port;
|
||||
use crate::hosts::replace_host;
|
||||
use crate::http_loader::HttpState;
|
||||
|
@ -127,7 +127,7 @@ fn process_ws_response(
|
|||
for cookie in response.headers().get_all(header::SET_COOKIE) {
|
||||
if let Ok(s) = std::str::from_utf8(cookie.as_bytes()) {
|
||||
if let Some(cookie) =
|
||||
Cookie::from_cookie_string(s.into(), resource_url, CookieSource::HTTP)
|
||||
ServoCookie::from_cookie_string(s.into(), resource_url, CookieSource::HTTP)
|
||||
{
|
||||
jar.push(cookie, resource_url, CookieSource::HTTP);
|
||||
}
|
||||
|
|
|
@ -20,6 +20,7 @@ use base::id::{BrowsingContextId, TopLevelBrowsingContextId};
|
|||
use base64::Engine;
|
||||
use capabilities::ServoCapabilities;
|
||||
use compositing_traits::ConstellationMsg;
|
||||
use cookie::{CookieBuilder, Expiration};
|
||||
use crossbeam_channel::{after, select, unbounded, Receiver, Sender};
|
||||
use euclid::{Rect, Size2D};
|
||||
use http::method::Method;
|
||||
|
@ -92,9 +93,10 @@ fn cookie_msg_to_cookie(cookie: cookie::Cookie) -> Cookie {
|
|||
value: cookie.value().to_owned(),
|
||||
path: cookie.path().map(|s| s.to_owned()),
|
||||
domain: cookie.domain().map(|s| s.to_owned()),
|
||||
expiry: cookie
|
||||
.expires()
|
||||
.map(|time| Date(time.to_timespec().sec as u64)),
|
||||
expiry: cookie.expires().and_then(|expiration| match expiration {
|
||||
Expiration::DateTime(date_time) => Some(Date(date_time.unix_timestamp() as u64)),
|
||||
Expiration::Session => None,
|
||||
}),
|
||||
secure: cookie.secure().unwrap_or(false),
|
||||
http_only: cookie.http_only().unwrap_or(false),
|
||||
same_site: cookie.same_site().map(|s| s.to_string()),
|
||||
|
@ -1254,19 +1256,19 @@ impl Handler {
|
|||
) -> WebDriverResult<WebDriverResponse> {
|
||||
let (sender, receiver) = ipc::channel().unwrap();
|
||||
|
||||
let cookie = cookie::Cookie::build(params.name.to_owned(), params.value.to_owned())
|
||||
let cookie_builder = CookieBuilder::new(params.name.to_owned(), params.value.to_owned())
|
||||
.secure(params.secure)
|
||||
.http_only(params.httpOnly);
|
||||
let cookie = match params.domain {
|
||||
Some(ref domain) => cookie.domain(domain.to_owned()),
|
||||
_ => cookie,
|
||||
let cookie_builder = match params.domain {
|
||||
Some(ref domain) => cookie_builder.domain(domain.to_owned()),
|
||||
_ => cookie_builder,
|
||||
};
|
||||
let cookie = match params.path {
|
||||
Some(ref path) => cookie.path(path.to_owned()).finish(),
|
||||
_ => cookie.finish(),
|
||||
let cookie_builder = match params.path {
|
||||
Some(ref path) => cookie_builder.path(path.to_owned()),
|
||||
_ => cookie_builder,
|
||||
};
|
||||
|
||||
let cmd = WebDriverScriptCommand::AddCookie(cookie, sender);
|
||||
let cmd = WebDriverScriptCommand::AddCookie(cookie_builder.build(), sender);
|
||||
self.browsing_context_script_command(cmd)?;
|
||||
match receiver.recv().unwrap() {
|
||||
Ok(_) => Ok(WebDriverResponse::Void),
|
||||
|
|
2
tests/wpt/meta/MANIFEST.json
vendored
2
tests/wpt/meta/MANIFEST.json
vendored
|
@ -662815,7 +662815,7 @@
|
|||
]
|
||||
],
|
||||
"document-cookie.html": [
|
||||
"2af65effeb291f829334d77a4072a41033f4e4a9",
|
||||
"5310fd8e8a36285dd1e9ae3d46042ec227eefa51",
|
||||
[
|
||||
null,
|
||||
{}
|
||||
|
|
|
@ -26,7 +26,7 @@ for (const i in TEST_CASES) {
|
|||
|
||||
// Cleanup
|
||||
if (document.cookie.includes("=")) {
|
||||
document.cookie = document.cookie.split("=")[0] + "=; expires=Thu, 01 Jan 1970 00:00:00 UTC";
|
||||
document.cookie = document.cookie.split("=")[0] + "=; expires=Thu, 01 Jan 1970 00:00:00 GMT";
|
||||
assert_equals(document.cookie, "");
|
||||
}
|
||||
}, t.name);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue