wreq-rb 0.6.2 → 0.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Cargo.lock +47 -21
- data/README.md +36 -0
- data/ext/wreq_rb/Cargo.toml +4 -4
- data/ext/wreq_rb/extconf.rb +10 -3
- data/ext/wreq_rb/src/client.rs +41 -0
- data/lib/wreq-rb/version.rb +1 -1
- data/patches/0002-add-preconnect.patch +266 -0
- data/vendor/wreq/Cargo.toml +11 -7
- data/vendor/wreq/bench/support/server.rs +2 -0
- data/vendor/wreq/src/client/layer/redirect/future.rs +1 -1
- data/vendor/wreq/src/client/layer/timeout/body.rs +16 -18
- data/vendor/wreq/src/client/layer/timeout/future.rs +2 -2
- data/vendor/wreq/src/client/request.rs +27 -15
- data/vendor/wreq/src/client/ws.rs +4 -3
- data/vendor/wreq/src/client.rs +4 -24
- data/vendor/wreq/src/conn/net/tcp.rs +16 -66
- data/vendor/wreq/src/conn/proxy/socks.rs +11 -1
- data/vendor/wreq/src/conn/proxy/tunnel.rs +14 -11
- data/vendor/wreq/src/conn/timeout.rs +1 -1
- data/vendor/wreq/src/cookie/jar.rs +170 -36
- data/vendor/wreq/src/cookie/store.rs +66 -4
- data/vendor/wreq/src/cookie.rs +48 -17
- data/vendor/wreq/src/dns.rs +2 -4
- data/vendor/wreq/src/error.rs +100 -0
- data/vendor/wreq/src/ext.rs +0 -49
- data/vendor/wreq/src/lib.rs +2 -0
- data/vendor/wreq/src/rt.rs +1 -14
- data/vendor/wreq/src/tls/trust/store.rs +35 -2
- data/vendor/wreq/tests/badssl.rs +3 -239
- data/vendor/wreq/tests/cert_store.rs +168 -0
- data/vendor/wreq/tests/client.rs +89 -0
- data/vendor/wreq/tests/proxy.rs +149 -3
- data/vendor/wreq/tests/redirect.rs +35 -0
- data/vendor/wreq/tests/support/tls_cert.rs +56 -0
- data/vendor/wreq/tests/timeouts.rs +25 -0
- data/vendor/wreq/tests/unix_socket.rs +109 -81
- data/vendor/wreq/tests/websocket.rs +40 -0
- metadata +9 -6
- data/vendor/wreq/examples/rt.rs +0 -23
|
@@ -5,6 +5,8 @@ use cookie::{
|
|
|
5
5
|
};
|
|
6
6
|
use http::{Uri, Version};
|
|
7
7
|
|
|
8
|
+
#[cfg(feature = "cookies-psl")]
|
|
9
|
+
use super::store::is_public_suffix;
|
|
8
10
|
use super::{
|
|
9
11
|
Cookie, CookieStore, Cookies, IntoCookie,
|
|
10
12
|
store::{DEFAULT_PATH, Store, canonical_host, cookie_is_expired, domain_match, normalize_path},
|
|
@@ -49,7 +51,7 @@ impl Jar {
|
|
|
49
51
|
let host = canonical_host(uri.host()?)?;
|
|
50
52
|
let now = OffsetDateTime::now_utc();
|
|
51
53
|
let store = self.0.read();
|
|
52
|
-
let
|
|
54
|
+
let entry = store
|
|
53
55
|
.cookies
|
|
54
56
|
.get(&host)?
|
|
55
57
|
.get(uri.path())?
|
|
@@ -57,7 +59,7 @@ impl Jar {
|
|
|
57
59
|
.filter(|entry| !cookie_is_expired(&entry.cookie, now))
|
|
58
60
|
.min_by_key(|entry| entry.creation_index)?;
|
|
59
61
|
|
|
60
|
-
Some(Cookie::from(
|
|
62
|
+
Some(Cookie::from(entry.cookie.clone()).with_host(host))
|
|
61
63
|
}
|
|
62
64
|
|
|
63
65
|
/// Returns whether an unexpired cookie exists for an exact URI scope.
|
|
@@ -70,6 +72,7 @@ impl Jar {
|
|
|
70
72
|
let Some(host) = uri.host().and_then(canonical_host) else {
|
|
71
73
|
return false;
|
|
72
74
|
};
|
|
75
|
+
|
|
73
76
|
let now = OffsetDateTime::now_utc();
|
|
74
77
|
|
|
75
78
|
self.0
|
|
@@ -84,20 +87,26 @@ impl Jar {
|
|
|
84
87
|
})
|
|
85
88
|
}
|
|
86
89
|
|
|
87
|
-
/// Returns all unexpired cookies in
|
|
90
|
+
/// Returns all unexpired cookies in creation order.
|
|
88
91
|
///
|
|
89
|
-
///
|
|
90
|
-
///
|
|
91
|
-
/// not broaden its domain scope. Snapshots are returned in creation order.
|
|
92
|
+
/// Each snapshot preserves its effective `Path` and canonical storage host. Host-only cookies
|
|
93
|
+
/// keep `Domain` absent; use [`Cookie::host`] when restoring them.
|
|
92
94
|
///
|
|
93
95
|
/// # Example
|
|
94
96
|
/// ```
|
|
95
97
|
/// use wreq::cookie::Jar;
|
|
96
|
-
/// let
|
|
97
|
-
///
|
|
98
|
-
///
|
|
99
|
-
///
|
|
98
|
+
/// let source = Jar::default();
|
|
99
|
+
/// source.add("session=abc; Secure", "https://example.com");
|
|
100
|
+
///
|
|
101
|
+
/// let target = Jar::default();
|
|
102
|
+
/// for cookie in source.get_all() {
|
|
103
|
+
/// if let Some(host) = cookie.host() {
|
|
104
|
+
/// let scheme = if cookie.secure() { "https" } else { "http" };
|
|
105
|
+
/// let uri = format!("{scheme}://{host}/");
|
|
106
|
+
/// target.add(cookie, uri);
|
|
107
|
+
/// }
|
|
100
108
|
/// }
|
|
109
|
+
/// assert_eq!(target.get_all().count(), 1);
|
|
101
110
|
/// ```
|
|
102
111
|
pub fn get_all(&self) -> impl Iterator<Item = Cookie<'static>> {
|
|
103
112
|
let now = OffsetDateTime::now_utc();
|
|
@@ -105,15 +114,16 @@ impl Jar {
|
|
|
105
114
|
.0
|
|
106
115
|
.read()
|
|
107
116
|
.cookies
|
|
108
|
-
.
|
|
109
|
-
.flat_map(|path_map| {
|
|
110
|
-
path_map.values().flat_map(|cookie_map| {
|
|
111
|
-
cookie_map.values().filter_map(|entry| {
|
|
117
|
+
.iter()
|
|
118
|
+
.flat_map(|(host, path_map)| {
|
|
119
|
+
path_map.values().flat_map(move |cookie_map| {
|
|
120
|
+
cookie_map.values().filter_map(move |entry| {
|
|
112
121
|
if cookie_is_expired(&entry.cookie, now) {
|
|
113
122
|
return None;
|
|
114
123
|
}
|
|
115
124
|
|
|
116
|
-
|
|
125
|
+
let cookie = Cookie::from(entry.cookie.clone()).with_host(host.clone());
|
|
126
|
+
Some((entry.creation_index, cookie))
|
|
117
127
|
})
|
|
118
128
|
})
|
|
119
129
|
})
|
|
@@ -187,7 +197,7 @@ impl Jar {
|
|
|
187
197
|
let store = self.0.read();
|
|
188
198
|
store
|
|
189
199
|
.matching_cookies(&uri, &host, now)
|
|
190
|
-
.map(|(
|
|
200
|
+
.map(|(host, _, entry)| Cookie::from(entry.cookie.clone()).with_host(host.clone()))
|
|
191
201
|
.collect::<Vec<_>>()
|
|
192
202
|
.into_iter()
|
|
193
203
|
}
|
|
@@ -234,8 +244,6 @@ impl Jar {
|
|
|
234
244
|
let Some(host) = uri.host().and_then(canonical_host) else {
|
|
235
245
|
return;
|
|
236
246
|
};
|
|
237
|
-
let host_only = cookie.domain().is_none();
|
|
238
|
-
|
|
239
247
|
// If the canonicalized request-host does not domain-match the
|
|
240
248
|
// domain-attribute:
|
|
241
249
|
// Ignore the cookie entirely and abort these steps.
|
|
@@ -251,11 +259,24 @@ impl Jar {
|
|
|
251
259
|
return;
|
|
252
260
|
}
|
|
253
261
|
|
|
254
|
-
|
|
262
|
+
#[cfg(feature = "cookies-psl")]
|
|
263
|
+
let public_suffix = is_public_suffix(&domain);
|
|
264
|
+
#[cfg(not(feature = "cookies-psl"))]
|
|
265
|
+
let public_suffix = false;
|
|
266
|
+
|
|
267
|
+
if public_suffix {
|
|
268
|
+
if domain != host {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
cookie.unset_domain();
|
|
272
|
+
} else {
|
|
273
|
+
cookie.set_domain(domain.to_string());
|
|
274
|
+
}
|
|
255
275
|
domain
|
|
256
276
|
} else {
|
|
257
277
|
host
|
|
258
278
|
};
|
|
279
|
+
let host_only = cookie.domain().is_none();
|
|
259
280
|
|
|
260
281
|
// Max-Age takes precedence over Expires and is relative to when the cookie is
|
|
261
282
|
// received. Store its effective deadline so every read path applies the same
|
|
@@ -294,6 +315,7 @@ impl Jar {
|
|
|
294
315
|
.to_owned();
|
|
295
316
|
|
|
296
317
|
let mut store = self.0.write();
|
|
318
|
+
store.evict_expired(now);
|
|
297
319
|
if !secure_origin
|
|
298
320
|
&& store.would_overlay_secure_cookie(cookie.name(), &domain, &path, now)
|
|
299
321
|
{
|
|
@@ -304,7 +326,7 @@ impl Jar {
|
|
|
304
326
|
store.remove_stored_cookie(&domain, &path, cookie.name(), host_only);
|
|
305
327
|
} else {
|
|
306
328
|
cookie.set_path(path.clone());
|
|
307
|
-
store.insert_stored_cookie(domain, path, cookie);
|
|
329
|
+
store.insert_stored_cookie(domain, path, cookie, now);
|
|
308
330
|
}
|
|
309
331
|
}
|
|
310
332
|
}
|
|
@@ -335,6 +357,7 @@ impl Jar {
|
|
|
335
357
|
};
|
|
336
358
|
let cookie = cookie.into();
|
|
337
359
|
let mut store = self.0.write();
|
|
360
|
+
store.evict_expired(OffsetDateTime::now_utc());
|
|
338
361
|
store.remove_stored_cookies(&host, uri.path(), cookie.name());
|
|
339
362
|
}
|
|
340
363
|
}
|
|
@@ -434,9 +457,14 @@ impl CookieStore for Jar {
|
|
|
434
457
|
|
|
435
458
|
#[cfg(test)]
|
|
436
459
|
mod tests {
|
|
437
|
-
use std::{
|
|
460
|
+
use std::{
|
|
461
|
+
net::{Ipv4Addr, Ipv6Addr},
|
|
462
|
+
thread,
|
|
463
|
+
time::Duration as StdDuration,
|
|
464
|
+
};
|
|
438
465
|
|
|
439
466
|
use http::{Uri, Version};
|
|
467
|
+
use url::Host;
|
|
440
468
|
|
|
441
469
|
use super::{CookieStore, Cookies, Jar};
|
|
442
470
|
|
|
@@ -514,6 +542,37 @@ mod tests {
|
|
|
514
542
|
assert_eq!(cookies[0].domain(), Some("example.com"));
|
|
515
543
|
}
|
|
516
544
|
|
|
545
|
+
#[test]
|
|
546
|
+
fn jar_applies_public_suffix_policy_only_with_psl() {
|
|
547
|
+
let psl_enabled = cfg!(feature = "cookies-psl");
|
|
548
|
+
for (cookie, uri) in [
|
|
549
|
+
("session=abc; Domain=com", "https://example.com/"),
|
|
550
|
+
("session=abc; Domain=com.", "https://example.com./"),
|
|
551
|
+
("session=abc; Domain=co.uk", "https://example.co.uk/"),
|
|
552
|
+
(
|
|
553
|
+
"session=abc; Domain=github.io",
|
|
554
|
+
"https://example.github.io/",
|
|
555
|
+
),
|
|
556
|
+
] {
|
|
557
|
+
let jar = Jar::default();
|
|
558
|
+
jar.add(cookie, uri);
|
|
559
|
+
assert_eq!(jar.is_empty(), psl_enabled, "{cookie} from {uri}");
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
let jar = Jar::default();
|
|
563
|
+
let origin = "https://co.uk/";
|
|
564
|
+
jar.add("session=abc; Domain=co.uk", origin);
|
|
565
|
+
let cookie = jar.get("session", origin).unwrap();
|
|
566
|
+
assert_eq!(cookie.domain().is_none(), psl_enabled);
|
|
567
|
+
assert_eq!(
|
|
568
|
+
jar.matches("https://sub.co.uk/").next().is_none(),
|
|
569
|
+
psl_enabled
|
|
570
|
+
);
|
|
571
|
+
|
|
572
|
+
jar.add("session=abc; Domain=co.uk; Max-Age=0", origin);
|
|
573
|
+
assert!(jar.is_empty());
|
|
574
|
+
}
|
|
575
|
+
|
|
517
576
|
#[test]
|
|
518
577
|
fn jar_rejects_secure_cookie_from_insecure_origin() {
|
|
519
578
|
let jar = Jar::default();
|
|
@@ -602,30 +661,60 @@ mod tests {
|
|
|
602
661
|
}
|
|
603
662
|
|
|
604
663
|
#[test]
|
|
605
|
-
fn
|
|
664
|
+
fn jar_get_all_preserves_storage_scope() {
|
|
606
665
|
let source = Jar::default();
|
|
607
666
|
source.add("session=abc", "http://example.com/foo/bar");
|
|
667
|
+
source.add("pref=dark; Domain=example.com", "http://www.example.com/");
|
|
668
|
+
source.add("secure=1; Secure", "https://secure.example/");
|
|
669
|
+
source.add("v6=1", "http://[::1]:8080/");
|
|
670
|
+
source.add("v4=1", "http://127.0.0.1:8080/");
|
|
608
671
|
|
|
609
672
|
let exported = source.get_all().collect::<Vec<_>>();
|
|
610
|
-
assert_eq!(exported.len(),
|
|
611
|
-
|
|
612
|
-
|
|
673
|
+
assert_eq!(exported.len(), 5);
|
|
674
|
+
|
|
675
|
+
let session = &exported[0];
|
|
676
|
+
assert_eq!(session.host(), Some(Host::Domain("example.com")));
|
|
677
|
+
assert_eq!(session.domain(), None);
|
|
678
|
+
assert_eq!(session.path(), Some("/foo"));
|
|
679
|
+
|
|
680
|
+
let pref = &exported[1];
|
|
681
|
+
assert_eq!(pref.host(), Some(Host::Domain("example.com")));
|
|
682
|
+
assert_eq!(pref.domain(), Some("example.com"));
|
|
683
|
+
assert_eq!(exported[2].host(), Some(Host::Domain("secure.example")));
|
|
684
|
+
assert_eq!(exported[3].host(), Some(Host::Ipv6(Ipv6Addr::LOCALHOST)));
|
|
685
|
+
assert_eq!(exported[4].host(), Some(Host::Ipv4(Ipv4Addr::LOCALHOST)));
|
|
686
|
+
|
|
687
|
+
let exact = source.get("session", "http://example.com/foo").unwrap();
|
|
688
|
+
assert_eq!(exact.host(), Some(Host::Domain("example.com")));
|
|
689
|
+
|
|
690
|
+
let matched = source
|
|
691
|
+
.matches("http://example.com/foo/bar")
|
|
692
|
+
.find(|cookie| cookie.name() == "session")
|
|
693
|
+
.unwrap();
|
|
694
|
+
assert_eq!(matched.host(), Some(Host::Domain("example.com")));
|
|
613
695
|
|
|
614
696
|
let target = Jar::default();
|
|
615
697
|
for cookie in exported {
|
|
616
|
-
|
|
698
|
+
let scheme = if cookie.secure() { "https" } else { "http" };
|
|
699
|
+
let uri = format!("{scheme}://{}/", cookie.host().unwrap());
|
|
700
|
+
target.add(cookie, uri);
|
|
617
701
|
}
|
|
618
702
|
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
703
|
+
for uri in [
|
|
704
|
+
"http://example.com/foo/bar",
|
|
705
|
+
"http://api.example.com/",
|
|
706
|
+
"https://secure.example/",
|
|
707
|
+
"http://secure.example/",
|
|
708
|
+
"http://[::1]:9999/",
|
|
709
|
+
"http://127.0.0.1:9999/",
|
|
710
|
+
] {
|
|
711
|
+
let uri = uri.parse::<Uri>().unwrap();
|
|
712
|
+
assert_eq!(
|
|
713
|
+
format!("{:?}", target.cookies(&uri, Version::HTTP_11)),
|
|
714
|
+
format!("{:?}", source.cookies(&uri, Version::HTTP_11)),
|
|
715
|
+
"restored jar should select the same cookies for {uri}"
|
|
716
|
+
);
|
|
717
|
+
}
|
|
629
718
|
}
|
|
630
719
|
|
|
631
720
|
#[test]
|
|
@@ -946,6 +1035,51 @@ mod tests {
|
|
|
946
1035
|
}
|
|
947
1036
|
}
|
|
948
1037
|
|
|
1038
|
+
#[test]
|
|
1039
|
+
fn jar_evicts_expired_cookies_and_reorders_reinserted_cookies() {
|
|
1040
|
+
use cookie::{
|
|
1041
|
+
Cookie as RawCookie,
|
|
1042
|
+
time::{Duration, OffsetDateTime},
|
|
1043
|
+
};
|
|
1044
|
+
|
|
1045
|
+
use super::canonical_host;
|
|
1046
|
+
|
|
1047
|
+
let jar = Jar::default();
|
|
1048
|
+
let host = canonical_host("example.com").unwrap();
|
|
1049
|
+
let expired_host = canonical_host("expired.example.com").unwrap();
|
|
1050
|
+
let now = OffsetDateTime::UNIX_EPOCH;
|
|
1051
|
+
let first_expiry = now + Duration::seconds(1);
|
|
1052
|
+
let expiry = first_expiry + Duration::seconds(1);
|
|
1053
|
+
{
|
|
1054
|
+
let mut store = jar.0.write();
|
|
1055
|
+
let mut obsolete = RawCookie::new("obsolete", "1");
|
|
1056
|
+
obsolete.set_expires(first_expiry);
|
|
1057
|
+
store.insert_stored_cookie(expired_host.clone(), "/".into(), obsolete.clone(), now);
|
|
1058
|
+
store.insert_stored_cookie(host.clone(), "/obsolete".into(), obsolete, now);
|
|
1059
|
+
|
|
1060
|
+
let mut session = RawCookie::new("session", "1");
|
|
1061
|
+
session.set_expires(expiry);
|
|
1062
|
+
store.insert_stored_cookie(host.clone(), "/".into(), session, now);
|
|
1063
|
+
store.insert_stored_cookie(host.clone(), "/".into(), RawCookie::new("other", "1"), now);
|
|
1064
|
+
|
|
1065
|
+
store.evict_expired(first_expiry);
|
|
1066
|
+
assert!(!store.cookies.contains_key(&expired_host));
|
|
1067
|
+
assert!(!store.cookies[&host].contains_key("/obsolete"));
|
|
1068
|
+
|
|
1069
|
+
// The next sweep is rate limited, so insertion must recognize the expired entry.
|
|
1070
|
+
store.evict_expired(expiry);
|
|
1071
|
+
let scope = &store.cookies[&host]["/"];
|
|
1072
|
+
assert!(scope.entries("session").next().is_some());
|
|
1073
|
+
store.insert_stored_cookie(host, "/".into(), RawCookie::new("session", "1"), expiry);
|
|
1074
|
+
}
|
|
1075
|
+
|
|
1076
|
+
let uri = Uri::from_static("https://example.com/");
|
|
1077
|
+
match jar.cookies(&uri, Version::HTTP_11) {
|
|
1078
|
+
Cookies::Compressed(value) => assert_eq!(value, "other=1; session=1"),
|
|
1079
|
+
other => panic!("expected compressed Cookie field, got {other:?}"),
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
|
|
949
1083
|
#[test]
|
|
950
1084
|
fn jar_sends_parent_domain_cookie_to_subdomain() {
|
|
951
1085
|
let jar = Jar::default();
|
|
@@ -11,6 +11,9 @@ use crate::ext::UriExt;
|
|
|
11
11
|
|
|
12
12
|
pub const DEFAULT_PATH: &str = "/";
|
|
13
13
|
|
|
14
|
+
/// Minimum interval between expiration sweeps of the store.
|
|
15
|
+
const EVICTION_INTERVAL: Duration = Duration::seconds(60);
|
|
16
|
+
|
|
14
17
|
/// Canonical immutable host used as a cookie domain key.
|
|
15
18
|
type CanonicalHost = Host<Box<str>>;
|
|
16
19
|
type NameMap = HashMap<Box<str>, CookieEntry>;
|
|
@@ -85,6 +88,11 @@ impl CookieScopeMap {
|
|
|
85
88
|
pub fn is_empty(&self) -> bool {
|
|
86
89
|
self.host_only.is_empty() && self.domain.is_empty()
|
|
87
90
|
}
|
|
91
|
+
|
|
92
|
+
fn retain(&mut self, mut keep: impl FnMut(&CookieEntry) -> bool) {
|
|
93
|
+
self.host_only.retain(|_, entry| keep(entry));
|
|
94
|
+
self.domain.retain(|_, entry| keep(entry));
|
|
95
|
+
}
|
|
88
96
|
}
|
|
89
97
|
|
|
90
98
|
/// Stores cookies by domain, path, host-only scope, and name.
|
|
@@ -92,21 +100,58 @@ impl CookieScopeMap {
|
|
|
92
100
|
pub struct Store {
|
|
93
101
|
pub cookies: DomainMap,
|
|
94
102
|
next_creation_index: u64,
|
|
103
|
+
/// Earliest known deadline. Removing a cookie can leave it earlier than necessary.
|
|
104
|
+
next_expiry: Option<OffsetDateTime>,
|
|
105
|
+
last_eviction: Option<OffsetDateTime>,
|
|
95
106
|
}
|
|
96
107
|
|
|
97
108
|
impl Store {
|
|
109
|
+
/// Prunes expired cookies and empty scopes at most once per eviction interval.
|
|
110
|
+
pub fn evict_expired(&mut self, now: OffsetDateTime) {
|
|
111
|
+
let due = self.next_expiry.is_some_and(|expiry| expiry <= now)
|
|
112
|
+
&& self
|
|
113
|
+
.last_eviction
|
|
114
|
+
.is_none_or(|last| now - last >= EVICTION_INTERVAL);
|
|
115
|
+
if !due {
|
|
116
|
+
return;
|
|
117
|
+
}
|
|
118
|
+
self.last_eviction = Some(now);
|
|
119
|
+
|
|
120
|
+
let mut next_expiry = None;
|
|
121
|
+
self.cookies.retain(|_, path_map| {
|
|
122
|
+
path_map.retain(|_, cookie_map| {
|
|
123
|
+
cookie_map.retain(|entry| {
|
|
124
|
+
if cookie_is_expired(&entry.cookie, now) {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
track_expiry(&mut next_expiry, &entry.cookie);
|
|
128
|
+
true
|
|
129
|
+
});
|
|
130
|
+
!cookie_map.is_empty()
|
|
131
|
+
});
|
|
132
|
+
!path_map.is_empty()
|
|
133
|
+
});
|
|
134
|
+
self.next_expiry = next_expiry;
|
|
135
|
+
|
|
136
|
+
let capacity = self.cookies.capacity();
|
|
137
|
+
if capacity > 16 && self.cookies.len() <= capacity / 4 {
|
|
138
|
+
self.cookies.shrink_to_fit();
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
98
142
|
/// Inserts or replaces a cookie in its domain and path scope.
|
|
99
143
|
pub fn insert_stored_cookie(
|
|
100
144
|
&mut self,
|
|
101
145
|
domain: CanonicalHost,
|
|
102
146
|
path: String,
|
|
103
147
|
cookie: RawCookie<'static>,
|
|
148
|
+
now: OffsetDateTime,
|
|
104
149
|
) {
|
|
105
150
|
let host_only = cookie.domain().is_none();
|
|
151
|
+
track_expiry(&mut self.next_expiry, &cookie);
|
|
106
152
|
|
|
107
|
-
//
|
|
108
|
-
//
|
|
109
|
-
// paths.
|
|
153
|
+
// During the interval between sweeps an expired entry can still occupy this slot.
|
|
154
|
+
// Chromium inherits the creation time for a live replacement with an unchanged value.
|
|
110
155
|
// https://chromium.googlesource.com/chromium/src/+/main/net/cookies/cookie_monster.cc
|
|
111
156
|
if let Some(entry) = self
|
|
112
157
|
.cookies
|
|
@@ -114,7 +159,7 @@ impl Store {
|
|
|
114
159
|
.and_then(|path_map| path_map.get_mut(path.as_str()))
|
|
115
160
|
.and_then(|cookie_map| cookie_map.get_mut(cookie.name(), host_only))
|
|
116
161
|
{
|
|
117
|
-
if entry.cookie.value() != cookie.value() {
|
|
162
|
+
if cookie_is_expired(&entry.cookie, now) || entry.cookie.value() != cookie.value() {
|
|
118
163
|
entry.creation_index = self.next_creation_index;
|
|
119
164
|
self.next_creation_index = self.next_creation_index.saturating_add(1);
|
|
120
165
|
}
|
|
@@ -231,6 +276,12 @@ impl Store {
|
|
|
231
276
|
}
|
|
232
277
|
}
|
|
233
278
|
|
|
279
|
+
fn track_expiry(next_expiry: &mut Option<OffsetDateTime>, cookie: &RawCookie<'_>) {
|
|
280
|
+
if let Some(expiry) = cookie.expires_datetime() {
|
|
281
|
+
*next_expiry = Some(next_expiry.map_or(expiry, |current| current.min(expiry)));
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
234
285
|
/// Applies the RFC 6265 request selection rules supported by this HTTP client.
|
|
235
286
|
fn request_matches_cookie(
|
|
236
287
|
uri: &Uri,
|
|
@@ -281,6 +332,17 @@ pub fn domain_match(host: &CanonicalHost, domain: &CanonicalHost) -> bool {
|
|
|
281
332
|
&& host.ends_with(domain.as_ref())
|
|
282
333
|
}
|
|
283
334
|
|
|
335
|
+
/// Checks the public suffix list, including its private entries, for a DNS domain.
|
|
336
|
+
/// https://www.rfc-editor.org/rfc/rfc6265.html#section-5.3
|
|
337
|
+
#[cfg(feature = "cookies-psl")]
|
|
338
|
+
pub fn is_public_suffix(domain: &CanonicalHost) -> bool {
|
|
339
|
+
let Host::Domain(domain) = domain else {
|
|
340
|
+
return false;
|
|
341
|
+
};
|
|
342
|
+
let domain = domain.strip_suffix('.').unwrap_or(domain);
|
|
343
|
+
psl::suffix_str(domain).is_some_and(|suffix| suffix == domain)
|
|
344
|
+
}
|
|
345
|
+
|
|
284
346
|
/// Determines whether `request_path` path-matches `cookie_path` under RFC 6265 section 5.1.4.
|
|
285
347
|
///
|
|
286
348
|
/// https://www.rfc-editor.org/rfc/rfc6265.html#section-5.1.4
|
data/vendor/wreq/src/cookie.rs
CHANGED
|
@@ -14,13 +14,17 @@ use std::{convert::TryInto, fmt, sync::Arc, time::SystemTime};
|
|
|
14
14
|
|
|
15
15
|
use cookie::{Cookie as RawCookie, Expiration, SameSite};
|
|
16
16
|
use http::{Uri, Version};
|
|
17
|
+
use url::Host;
|
|
17
18
|
|
|
18
19
|
pub use self::jar::Jar;
|
|
19
20
|
use crate::{error::Error, header::HeaderValue};
|
|
20
21
|
|
|
21
|
-
/// A parsed HTTP cookie.
|
|
22
|
+
/// A parsed HTTP cookie with optional [`Jar`] storage metadata.
|
|
22
23
|
#[derive(Debug, Clone)]
|
|
23
|
-
pub struct Cookie<'a>
|
|
24
|
+
pub struct Cookie<'a> {
|
|
25
|
+
inner: RawCookie<'a>,
|
|
26
|
+
host: Option<Host<Box<str>>>,
|
|
27
|
+
}
|
|
24
28
|
|
|
25
29
|
impl<'a> Cookie<'a> {
|
|
26
30
|
pub(crate) fn parse(value: &'a HeaderValue) -> crate::Result<Cookie<'a>> {
|
|
@@ -28,13 +32,22 @@ impl<'a> Cookie<'a> {
|
|
|
28
32
|
.map_err(cookie::ParseError::from)
|
|
29
33
|
.and_then(cookie::Cookie::parse)
|
|
30
34
|
.map_err(Error::decode)
|
|
31
|
-
.map(Cookie
|
|
35
|
+
.map(|cookie| Cookie {
|
|
36
|
+
inner: cookie,
|
|
37
|
+
host: None,
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
#[inline]
|
|
42
|
+
fn with_host(mut self, host: Host<Box<str>>) -> Self {
|
|
43
|
+
self.host = Some(host);
|
|
44
|
+
self
|
|
32
45
|
}
|
|
33
46
|
|
|
34
47
|
/// Returns the name of `self`.
|
|
35
48
|
#[inline]
|
|
36
49
|
pub fn name(&self) -> &str {
|
|
37
|
-
self.
|
|
50
|
+
self.inner.name()
|
|
38
51
|
}
|
|
39
52
|
|
|
40
53
|
/// Returns the value of `self`.
|
|
@@ -42,37 +55,37 @@ impl<'a> Cookie<'a> {
|
|
|
42
55
|
/// Does not strip surrounding quotes.
|
|
43
56
|
#[inline]
|
|
44
57
|
pub fn value(&self) -> &str {
|
|
45
|
-
self.
|
|
58
|
+
self.inner.value()
|
|
46
59
|
}
|
|
47
60
|
|
|
48
61
|
/// Returns whether this cookie was marked `HttpOnly` or not.
|
|
49
62
|
#[inline]
|
|
50
63
|
pub fn http_only(&self) -> bool {
|
|
51
|
-
self.
|
|
64
|
+
self.inner.http_only().unwrap_or(false)
|
|
52
65
|
}
|
|
53
66
|
|
|
54
67
|
/// Returns whether this cookie was marked `Secure` or not.
|
|
55
68
|
#[inline]
|
|
56
69
|
pub fn secure(&self) -> bool {
|
|
57
|
-
self.
|
|
70
|
+
self.inner.secure().unwrap_or(false)
|
|
58
71
|
}
|
|
59
72
|
|
|
60
73
|
/// Returns whether the `SameSite` attribute of this cookie is `Lax`.
|
|
61
74
|
#[inline]
|
|
62
75
|
pub fn same_site_lax(&self) -> bool {
|
|
63
|
-
self.
|
|
76
|
+
self.inner.same_site() == Some(SameSite::Lax)
|
|
64
77
|
}
|
|
65
78
|
|
|
66
79
|
/// Returns whether the `SameSite` attribute of this cookie is `Strict`.
|
|
67
80
|
#[inline]
|
|
68
81
|
pub fn same_site_strict(&self) -> bool {
|
|
69
|
-
self.
|
|
82
|
+
self.inner.same_site() == Some(SameSite::Strict)
|
|
70
83
|
}
|
|
71
84
|
|
|
72
85
|
/// Returns the `Path` of the cookie if one was specified.
|
|
73
86
|
#[inline]
|
|
74
87
|
pub fn path(&self) -> Option<&str> {
|
|
75
|
-
self.
|
|
88
|
+
self.inner.path()
|
|
76
89
|
}
|
|
77
90
|
|
|
78
91
|
/// Returns the `Domain` of the cookie if one was specified.
|
|
@@ -82,13 +95,25 @@ impl<'a> Cookie<'a> {
|
|
|
82
95
|
/// stripped.
|
|
83
96
|
#[inline]
|
|
84
97
|
pub fn domain(&self) -> Option<&str> {
|
|
85
|
-
self.
|
|
98
|
+
self.inner.domain()
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/// Returns the canonical host used to store this cookie.
|
|
102
|
+
///
|
|
103
|
+
/// Cookies returned by [`Jar`] query methods include this value.
|
|
104
|
+
#[inline]
|
|
105
|
+
pub fn host(&self) -> Option<Host<&str>> {
|
|
106
|
+
self.host.as_ref().map(|host| match host {
|
|
107
|
+
Host::Domain(domain) => Host::Domain(domain.as_ref()),
|
|
108
|
+
Host::Ipv4(address) => Host::Ipv4(*address),
|
|
109
|
+
Host::Ipv6(address) => Host::Ipv6(*address),
|
|
110
|
+
})
|
|
86
111
|
}
|
|
87
112
|
|
|
88
113
|
/// Returns the specified max-age of the cookie if it is non-negative and representable.
|
|
89
114
|
#[inline]
|
|
90
115
|
pub fn max_age(&self) -> Option<std::time::Duration> {
|
|
91
|
-
self.
|
|
116
|
+
self.inner.max_age().and_then(|d| d.try_into().ok())
|
|
92
117
|
}
|
|
93
118
|
|
|
94
119
|
/// Returns the expiration date-time of the cookie if one was specified.
|
|
@@ -96,7 +121,7 @@ impl<'a> Cookie<'a> {
|
|
|
96
121
|
/// Session cookies return `None`.
|
|
97
122
|
#[inline]
|
|
98
123
|
pub fn expires(&self) -> Option<SystemTime> {
|
|
99
|
-
match self.
|
|
124
|
+
match self.inner.expires() {
|
|
100
125
|
Some(Expiration::DateTime(offset)) => Some(SystemTime::from(offset)),
|
|
101
126
|
None | Some(Expiration::Session) => None,
|
|
102
127
|
}
|
|
@@ -105,28 +130,34 @@ impl<'a> Cookie<'a> {
|
|
|
105
130
|
/// Converts `self` into a `Cookie` with a static lifetime with as few allocations as possible.
|
|
106
131
|
#[inline]
|
|
107
132
|
pub fn into_owned(self) -> Cookie<'static> {
|
|
108
|
-
Cookie
|
|
133
|
+
Cookie {
|
|
134
|
+
inner: self.inner.into_owned(),
|
|
135
|
+
host: self.host,
|
|
136
|
+
}
|
|
109
137
|
}
|
|
110
138
|
}
|
|
111
139
|
|
|
112
140
|
impl fmt::Display for Cookie<'_> {
|
|
113
141
|
#[inline]
|
|
114
142
|
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
|
115
|
-
self.
|
|
143
|
+
self.inner.fmt(f)
|
|
116
144
|
}
|
|
117
145
|
}
|
|
118
146
|
|
|
119
147
|
impl<'c> From<RawCookie<'c>> for Cookie<'c> {
|
|
120
148
|
#[inline]
|
|
121
149
|
fn from(cookie: RawCookie<'c>) -> Cookie<'c> {
|
|
122
|
-
Cookie
|
|
150
|
+
Cookie {
|
|
151
|
+
inner: cookie,
|
|
152
|
+
host: None,
|
|
153
|
+
}
|
|
123
154
|
}
|
|
124
155
|
}
|
|
125
156
|
|
|
126
157
|
impl<'c> From<Cookie<'c>> for RawCookie<'c> {
|
|
127
158
|
#[inline]
|
|
128
159
|
fn from(cookie: Cookie<'c>) -> RawCookie<'c> {
|
|
129
|
-
cookie.
|
|
160
|
+
cookie.inner
|
|
130
161
|
}
|
|
131
162
|
}
|
|
132
163
|
|
data/vendor/wreq/src/dns.rs
CHANGED
|
@@ -11,11 +11,9 @@ mod resolve;
|
|
|
11
11
|
#[cfg(feature = "hickory-dns")]
|
|
12
12
|
pub(crate) mod hickory;
|
|
13
13
|
|
|
14
|
-
pub use self::{
|
|
15
|
-
gai::GaiResolver,
|
|
16
|
-
resolve::{Addrs, IntoResolve, Name, Resolve, Resolving},
|
|
17
|
-
};
|
|
14
|
+
pub use self::resolve::{Addrs, IntoResolve, Name, Resolve, Resolving};
|
|
18
15
|
pub(crate) use self::{
|
|
16
|
+
gai::GaiResolver,
|
|
19
17
|
resolve::{DnsResolverWithOverrides, DynResolver},
|
|
20
18
|
sealed::{DnsResolver, resolve},
|
|
21
19
|
};
|