aboutsummaryrefslogtreecommitdiff
path: root/src/modules/mod.rs
blob: 61f4b74021d294558361bf450455171304400f46 (plain)
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
use crate::error::ServiceError;
use crate::State;
use bytes::Bytes;
use futures::Future;
use http_body_util::combinators::BoxBody;
use hyper::{Request, Response};
use serde_yml::Value;
use std::{net::SocketAddr, pin::Pin, sync::Arc};

mod accesslog;
mod auth;
mod cache;
mod cgi;
mod debug;
mod error;
pub mod fallback;
mod file;
mod files;
mod headers;
mod hosts;
mod inspect;
mod loadbalance;
mod paths;
mod proxy;
mod redirect;
mod switch;
mod upgrade_insecure;

pub type NodeRequest = Request<BoxBody<Bytes, hyper::Error>>;
pub type NodeResponse = Response<BoxBody<Bytes, ServiceError>>;

pub static MODULES: &[&dyn NodeKind] = &[
    &auth::basic::HttpBasicAuthKind,
    &auth::cookie::CookieAuthKind,
    &auth::openid::OpenIDAuthKind,
    &proxy::ProxyKind,
    &hosts::HostsKind,
    &paths::PathsKind,
    &files::FilesKind,
    &file::FileKind,
    &accesslog::AccessLogKind,
    &error::ErrorKind,
    &headers::HeadersKind,
    &switch::SwitchKind,
    &redirect::RedirectKind,
    &cgi::CgiKind,
    &debug::DebugKind,
    &cache::CacheKind,
    &loadbalance::LoadBalanceKind,
    &upgrade_insecure::UpgradeInsecureKind,
    &inspect::InspectKind,
    &fallback::FallbackKind,
];

pub struct NodeContext {
    pub state: Arc<State>,
    pub addr: SocketAddr,
    pub secure: bool,
    pub listen_addr: SocketAddr,
}

pub trait NodeKind: Send + Sync + 'static {
    fn name(&self) -> &'static str;
    fn instanciate(&self, config: Value) -> anyhow::Result<Arc<dyn Node>>;
}
pub trait Node: Send + Sync + 'static {
    fn handle<'a>(
        &'a self,
        context: &'a mut NodeContext,
        request: NodeRequest,
    ) -> Pin<Box<dyn Future<Output = Result<NodeResponse, ServiceError>> + Send + Sync + 'a>>;
}