aboutsummaryrefslogtreecommitdiff
path: root/src/filters/hosts.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2024-05-30 00:09:11 +0200
committermetamuffin <metamuffin@disroot.org>2024-05-30 00:09:11 +0200
commit532cc431d1c5ca1ffcf429a4ccb94edc7848fe7a (patch)
treec4422c4d54e01f63bae391cd95788cad74f59fbb /src/filters/hosts.rs
parent8b39940a58c28bc1bbe291eb5229e9ce1444e33c (diff)
downloadgnix-532cc431d1c5ca1ffcf429a4ccb94edc7848fe7a.tar
gnix-532cc431d1c5ca1ffcf429a4ccb94edc7848fe7a.tar.bz2
gnix-532cc431d1c5ca1ffcf429a4ccb94edc7848fe7a.tar.zst
rename filters dir
Diffstat (limited to 'src/filters/hosts.rs')
-rw-r--r--src/filters/hosts.rs45
1 files changed, 0 insertions, 45 deletions
diff --git a/src/filters/hosts.rs b/src/filters/hosts.rs
deleted file mode 100644
index 286d478..0000000
--- a/src/filters/hosts.rs
+++ /dev/null
@@ -1,45 +0,0 @@
-use super::{Node, NodeContext, NodeKind, NodeRequest, NodeResponse};
-use crate::{config::DynNode, error::ServiceError};
-use futures::Future;
-use hyper::header::HOST;
-use serde::Deserialize;
-use serde_yaml::Value;
-use std::{collections::HashMap, pin::Pin, sync::Arc};
-
-#[derive(Deserialize)]
-#[serde(transparent)]
-struct Hosts(HashMap<String, DynNode>);
-
-pub struct HostsKind;
-impl NodeKind for HostsKind {
- fn name(&self) -> &'static str {
- "hosts"
- }
- fn instanciate(&self, config: Value) -> anyhow::Result<Arc<dyn Node>> {
- Ok(Arc::new(serde_yaml::from_value::<Hosts>(config)?))
- }
-}
-impl Node for Hosts {
- fn handle<'a>(
- &'a self,
- context: &'a mut NodeContext,
- request: NodeRequest,
- ) -> Pin<Box<dyn Future<Output = Result<NodeResponse, ServiceError>> + Send + Sync + 'a>> {
- Box::pin(async move {
- let host = request
- .headers()
- .get(HOST)
- .and_then(|e| e.to_str().ok())
- .ok_or(ServiceError::NoHost)?;
-
- let host = remove_port(&host);
- let node = self.0.get(host).ok_or(ServiceError::UnknownHost)?;
-
- node.handle(context, request).await
- })
- }
-}
-
-pub fn remove_port(s: &str) -> &str {
- s.split_once(":").map(|(s, _)| s).unwrap_or(s)
-}