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
use futures::Future;
use error::{Error, Result};
use httprequest::HttpRequest;
use httpresponse::HttpResponse;
mod logger;
pub mod cors;
pub mod csrf;
mod defaultheaders;
mod errhandlers;
#[cfg(feature = "session")]
pub mod identity;
#[cfg(feature = "session")]
pub mod session;
pub use self::defaultheaders::DefaultHeaders;
pub use self::errhandlers::ErrorHandlers;
pub use self::logger::Logger;
pub enum Started {
Done,
Response(HttpResponse),
Future(Box<Future<Item = Option<HttpResponse>, Error = Error>>),
}
pub enum Response {
Done(HttpResponse),
Future(Box<Future<Item = HttpResponse, Error = Error>>),
}
pub enum Finished {
Done,
Future(Box<Future<Item = (), Error = Error>>),
}
#[allow(unused_variables)]
pub trait Middleware<S>: 'static {
fn start(&self, req: &HttpRequest<S>) -> Result<Started> {
Ok(Started::Done)
}
fn response(&self, req: &HttpRequest<S>, resp: HttpResponse) -> Result<Response> {
Ok(Response::Done(resp))
}
fn finish(&self, req: &HttpRequest<S>, resp: &HttpResponse) -> Finished {
Finished::Done
}
}