aboutsummaryrefslogtreecommitdiff
path: root/src/modules/mod.rs
blob: b267a045377825b25983fa9e9f7f402ac49f567c (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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
    This file is part of gnix (https://codeberg.org/metamuffin/gnix)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2025 metamuffin <metamuffin.org>
*/
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 delay;
mod error;
mod fallback;
mod file;
mod files;
mod headers;
mod hosts;
mod inspect;
mod limits;
mod loadbalance;
mod log;
mod paths;
mod proxy;
mod ratelimit;
mod redirect;
mod semaphore;
mod switch;
mod upgrade_insecure;

pub type NodeRequest = Request<BoxBody<Bytes, ServiceError>>;
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,
    &limits::LimitsKind,
    &delay::DelayKind,
    &ratelimit::RatelimitKind,
    &log::LogKind,
    &semaphore::SemaphoreKind,
];

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>>;
}