From d1feb3df35e491391a1600cbde00db9406629b3f Mon Sep 17 00:00:00 2001 From: metamuffin Date: Wed, 19 Mar 2025 19:06:45 +0100 Subject: debug method and switch http version --- src/modules/switch.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/modules/switch.rs') 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 + } + } } } } -- cgit v1.2.3-70-g09d2