feat(trusted-proxies): add switchable simple and legacy modes (#2674)

Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com>
Co-authored-by: houseme <4829346+houseme@users.noreply.github.com>
This commit is contained in:
houseme
2026-04-25 09:25:32 +08:00
committed by GitHub
parent f833cd9cbe
commit 7215761784
10 changed files with 606 additions and 34 deletions
@@ -17,9 +17,9 @@
use std::sync::Arc;
use tower::Layer;
use crate::LegacyTrustedProxyMiddleware;
use crate::ProxyValidator;
use crate::TrustedProxyConfig;
use crate::TrustedProxyMiddleware;
use crate::{CacheConfig, ProxyMetrics};
/// Tower Layer for the trusted proxy middleware.
@@ -73,10 +73,10 @@ impl TrustedProxyLayer {
}
impl<S> Layer<S> for TrustedProxyLayer {
type Service = TrustedProxyMiddleware<S>;
type Service = LegacyTrustedProxyMiddleware<S>;
fn layer(&self, inner: S) -> Self::Service {
TrustedProxyMiddleware {
LegacyTrustedProxyMiddleware {
inner,
validator: self.validator.clone(),
enabled: self.enabled,
@@ -14,7 +14,7 @@
//! Tower service implementation for the trusted proxy middleware.
use crate::{ClientInfo, ProxyValidator, TrustedProxyLayer};
use crate::{ClientInfo, ProxyValidator};
use http::Request;
use std::sync::Arc;
use std::task::{Context, Poll};
@@ -43,7 +43,7 @@ impl<S> TrustedProxyMiddleware<S> {
}
/// Creates a new `TrustedProxyMiddleware` from a `TrustedProxyLayer`.
pub fn from_layer(inner: S, layer: &TrustedProxyLayer) -> Self {
pub fn from_layer(inner: S, layer: &super::layer::TrustedProxyLayer) -> Self {
Self::new(inner, layer.validator.clone(), layer.enabled)
}
}