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

use std::sync::Arc;
use std::ops::Deref;
use futures::Future;
use hyper::server::{Request, Response};
use Shared;

pub struct PluginData<S>
{
    pub shared: Arc<Shared<S>>,
    pub request: Request,
    pub response: Response,
    pub session_id: Option<String>,
}

/// A plugin provides a handler for a request.
///
/// Code within these handlers should take care not to block or call
/// functions which may block. Instead, it should return futures immediately, or None.
///
/// In the case of an error, if at all possible, respond to the client with a 5xx
/// error code and return a Response rather than returning an Error through the
/// future.  However, either way works.
pub trait Plugin<S,E>
{
    fn handle(&self, data: PluginData<S>)
              -> Box<Future<Item = PluginData<S>, Error = E>>;
}

/// Anything that dereferences into a Plugin also implements Plugin
impl<S,E,R,T> Plugin<S,E> for T
    where T: Deref<Target = R>,
          R: Plugin<S,E>
{
    fn handle(&self, data: PluginData<S>)
              -> Box<Future<Item = PluginData<S>, Error = E>>
    {
        self.deref().handle(data)
    }
}


pub mod router;
pub use self::router::{Router, Handler};

pub mod page_visits;
pub use self::page_visits::PageVisits;

pub mod htdocs;
pub use self::htdocs::Htdocs;

pub mod session;
pub use self::session::Session;

pub mod good_citizen;
pub use self::good_citizen::GoodCitizen;