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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
use std::borrow::ToOwned;
use hyper;
use hyper::mime::Mime;
pub use hyper::server::Listening;
use filter::{ContextFilter, ResponseFilter};
use handler::HandleRequest;
use net::SslServer;
use HttpResult;
pub use self::instance::ServerInstance;
pub use self::config::{Host, Global, KeepAlive};
mod instance;
mod config;
pub struct Server<R> {
pub handlers: R,
pub host: Host,
pub threads: Option<usize>,
pub keep_alive: Option<KeepAlive>,
pub server: String,
pub content_type: Mime,
pub global: Global,
pub context_filters: Vec<Box<ContextFilter>>,
pub response_filters: Vec<Box<ResponseFilter>>
}
impl<R: HandleRequest> Server<R> {
pub fn new(handlers: R) -> Server<R> {
Server {
handlers: handlers,
host: 80.into(),
threads: None,
keep_alive: None,
server: "rustful".to_owned(),
content_type: Mime(
hyper::mime::TopLevel::Text,
hyper::mime::SubLevel::Html,
vec![(hyper::mime::Attr::Charset, hyper::mime::Value::Utf8)]
),
global: Global::default(),
context_filters: Vec::new(),
response_filters: Vec::new(),
}
}
pub fn run(self) -> HttpResult<Listening> {
self.build().run()
}
pub fn run_https<S: SslServer + Clone + Send + 'static>(self, ssl: S) -> HttpResult<Listening> {
self.build().run_https(ssl)
}
pub fn build(self) -> ServerInstance<R> {
ServerInstance::new(self)
}
}
impl<R: Default + HandleRequest> Default for Server<R> {
fn default() -> Server<R> {
Server::new(R::default())
}
}