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
|
use crate::error::ServiceError;
use crate::State;
use bytes::Bytes;
use futures::Future;
use http_body_util::combinators::BoxBody;
use hyper::{body::Incoming, Request, Response};
use serde_yaml::Value;
use std::{net::SocketAddr, pin::Pin, sync::Arc};
pub mod accesslog;
pub mod auth;
pub mod cgi;
pub mod debug;
pub mod error;
pub mod file;
pub mod files;
pub mod headers;
pub mod hosts;
pub mod paths;
pub mod proxy;
pub mod redirect;
pub mod switch;
pub type NodeRequest = Request<Incoming>;
pub type NodeResponse = Response<BoxBody<Bytes, ServiceError>>;
pub static MODULES: &[&dyn NodeKind] = &[
&auth::basic::HttpBasicAuthKind,
&auth::cookie::CookieAuthKind,
&proxy::ProxyKind,
&hosts::HostsKind,
&paths::PathsKind,
&files::FilesKind,
&file::FileKind,
&accesslog::AccessLogKind,
&error::ErrorKind,
&headers::HeadersKind,
&switch::SwitchKind,
&redirect::RedirectKind,
&cgi::CgiKind,
&debug::DebugKind,
];
pub struct NodeContext {
pub state: Arc<State>,
pub 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>>;
}
|