aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-03-19 19:06:45 +0100
committermetamuffin <metamuffin@disroot.org>2025-03-19 19:06:45 +0100
commitd1feb3df35e491391a1600cbde00db9406629b3f (patch)
treeb8e6fb0e3a393b37589f9384eb05dca5aa6e1000 /src
parent7ae389f3b165a7b4f9b17ef96545f5430cfcd7bc (diff)
downloadgnix-d1feb3df35e491391a1600cbde00db9406629b3f.tar
gnix-d1feb3df35e491391a1600cbde00db9406629b3f.tar.bz2
gnix-d1feb3df35e491391a1600cbde00db9406629b3f.tar.zst
debug method and switch http version
Diffstat (limited to 'src')
-rw-r--r--src/modules/debug.rs3
-rw-r--r--src/modules/switch.rs17
2 files changed, 19 insertions, 1 deletions
diff --git a/src/modules/debug.rs b/src/modules/debug.rs
index f0cfb98..42d023a 100644
--- a/src/modules/debug.rs
+++ b/src/modules/debug.rs
@@ -29,9 +29,10 @@ impl Node for Debug {
) -> Pin<Box<dyn Future<Output = Result<NodeResponse, ServiceError>> + Send + Sync + 'a>> {
Box::pin(async move {
let s = format!(
- "address: {:?}\nversion: {:?}\nuri: {:?}\nheaders: {:#?}",
+ "address: {:?}\nversion: {:?}\nmethod: {:?}\nuri: {:?}\nheaders: {:#?}",
context.addr,
request.version(),
+ request.method(),
request.uri(),
request.headers(),
);
diff --git a/src/modules/switch.rs b/src/modules/switch.rs
index 289c406..466bdd8 100644
--- a/src/modules/switch.rs
+++ b/src/modules/switch.rs
@@ -3,6 +3,7 @@ use crate::{config::DynNode, error::ServiceError};
use anyhow::Result;
use futures::Future;
use headers::{HeaderMapExt, Upgrade};
+use http::Version;
use hyper::Method;
use serde::Deserialize;
use std::{pin::Pin, sync::Arc};
@@ -52,9 +53,13 @@ enum Condition {
IsWebsocketUpgrade,
IsPost,
IsGet,
+ IsPut,
+ IsPatch,
+ IsOptions,
HasHeader(String),
PathStartsWith(String),
PathIs(String),
+ HttpVersion(u8),
}
impl Condition {
@@ -66,10 +71,22 @@ impl Condition {
Condition::HasHeader(name) => req.headers().contains_key(name),
Condition::PathStartsWith(path_prefix) => req.uri().path().starts_with(path_prefix),
Condition::PathIs(path) => req.uri().path() == path,
+ Condition::IsPut => req.method() == Method::PUT,
+ Condition::IsPatch => req.method() == Method::PATCH,
+ Condition::IsOptions => req.method() == Method::OPTIONS,
Condition::IsPost => req.method() == Method::POST,
Condition::IsGet => req.method() == Method::GET,
Condition::Any(conds) => conds.iter().any(|c| c.test(req)),
Condition::All(conds) => conds.iter().all(|c| c.test(req)),
+ Condition::HttpVersion(n) => {
+ if req.version() == Version::HTTP_3 {
+ *n == 3
+ } else if req.version() == Version::HTTP_2 {
+ *n == 2
+ } else {
+ *n == 1
+ }
+ }
}
}
}