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
use crate::scheme::RedirectScheme;
#[derive(Clone, Default)]
pub struct RedirectSchemeBuilder {
https_to_http: bool,
temporary: bool,
replacements: Vec<(String, String)>,
}
impl RedirectSchemeBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn http_to_https(&mut self, value: bool) -> &mut Self {
let mut new = self;
new.https_to_http = !value;
new
}
pub fn https_to_http(&mut self) -> &mut Self {
let mut new = self;
new.https_to_http = true;
new
}
pub fn permanent(&mut self, value: bool) -> &mut Self {
let mut new = self;
new.temporary = !value;
new
}
pub fn temporary(&mut self) -> &mut Self {
let mut new = self;
new.temporary = true;
new
}
pub fn replacements(&mut self, value: &[(&str, &str)]) -> &mut Self {
let mut new = self;
new.replacements = value
.iter()
.map(|(a, b)| ((*a).into(), (*b).into()))
.collect();
new
}
pub fn build(&self) -> RedirectScheme {
RedirectScheme {
https_to_http: self.https_to_http,
temporary: self.temporary,
replacements: self.replacements.clone(),
}
}
}