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