pub struct UserAgentLayer { /* private fields */ }Expand description
Tower layer that sanitizes the inbound User-Agent header in place.
Reads the request’s User-Agent once, applies a small set of
normalization rules (length cap on a UTF-8 char boundary, ASCII control
stripping, whitespace collapsing, trimming), and rewrites the header value
before delegating to the inner service. If the sanitized result is empty
the header is removed entirely so downstream consumers see the same
“missing” state they handle today.
Because the layer mutates the request header itself, every downstream
reader — ClientInfo, the cookie session middleware, audit logging,
fingerprint hashing — observes the cleaned value with no further plumbing.
§Layer ordering
Install UserAgentLayer before any layer or handler that reads
User-Agent. In axum that means it must be added with a .layer(...)
call that comes after (i.e. wraps) the consumer:
use axum::{Router, routing::get};
use modo::middleware::UserAgentLayer;
let app: Router = Router::new()
.route("/", get(|| async { "ok" }))
.layer(UserAgentLayer::new());Implementations§
Source§impl UserAgentLayer
impl UserAgentLayer
Sourcepub fn with_max_length(max_len: usize) -> Self
pub fn with_max_length(max_len: usize) -> Self
Create a layer with a custom byte-length cap.
Trait Implementations§
Source§impl Clone for UserAgentLayer
impl Clone for UserAgentLayer
Source§fn clone(&self) -> UserAgentLayer
fn clone(&self) -> UserAgentLayer
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more