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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
use std::sync::Arc;
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum EncodingSupport {
Never,
TextFiles,
AllFiles,
}
#[derive(Clone, Debug)]
pub struct Config {
pub(crate) text_charset: Option<String>,
pub(crate) index_files: Vec<String>,
pub(crate) encoding_support: EncodingSupport,
pub(crate) content_type: bool,
pub(crate) etag: bool,
pub(crate) last_modified: bool,
}
impl Config {
pub fn new() -> Config {
Config {
text_charset: Some(String::from("utf-8")),
index_files: Vec::new(),
encoding_support: EncodingSupport::TextFiles,
content_type: true,
etag: true,
last_modified: true,
}
}
pub fn text_charset(&mut self, charset: &str) -> &mut Self {
self.text_charset = Some(charset.into());
self
}
pub fn no_text_charset(&mut self) -> &mut Self {
self.text_charset = None;
self
}
pub fn add_index_file(&mut self, name: &str) -> &mut Self {
self.index_files.push(String::from(name));
self
}
pub fn no_encodings(&mut self) -> &mut Self {
self.encoding_support = EncodingSupport::Never;
self
}
pub fn encodings_on_text_files(&mut self) -> &mut Self {
self.encoding_support = EncodingSupport::TextFiles;
self
}
pub fn encodings_on_all_files(&mut self) -> &mut Self {
self.encoding_support = EncodingSupport::AllFiles;
self
}
pub fn content_type(&mut self, value: bool) -> &mut Self {
self.content_type = value;
self
}
pub fn etag(&mut self, value: bool) -> &mut Self {
self.etag = value;
self
}
pub fn last_modified(&mut self, value: bool) -> &mut Self {
self.last_modified = value;
self
}
pub fn done(&self) -> Arc<Config> {
Arc::new(self.clone())
}
}