1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
use std::time::Duration;
use cookie::SameSite;
#[derive(Debug)]
pub struct CookieOptions {
pub name: String,
pub path: String,
pub max_age: Duration,
pub secure: Option<bool>,
pub domain: Option<String>,
pub http_only: Option<bool>,
pub same_site: Option<SameSite>,
}
impl CookieOptions {
pub fn new() -> Self {
Self {
domain: None,
secure: None,
http_only: None,
same_site: None,
path: "/".into(),
name: "viz.sid".into(),
max_age: Duration::from_secs(3600 * 24),
}
}
pub fn with_name(mut self, name: String) -> Self {
self.name = name;
self
}
pub fn with_max_age(mut self, max_age: Duration) -> Self {
self.max_age = max_age;
self
}
pub fn with_domain(mut self, domain: String) -> Self {
self.domain.replace(domain);
self
}
pub fn with_path(mut self, path: String) -> Self {
self.path = path;
self
}
pub fn with_secure(mut self, secure: bool) -> Self {
self.secure.replace(secure);
self
}
pub fn with_http_only(mut self, http_only: bool) -> Self {
self.http_only.replace(http_only);
self
}
pub fn with_same_site(mut self, same_site: SameSite) -> Self {
self.same_site.replace(same_site);
self
}
}
impl Default for CookieOptions {
fn default() -> Self {
Self::new()
}
}