expression

Axum: mark an authorization header sensitive

Mark sensitive header values to reduce accidental exposure through Debug output. This flag is a hint, not encryption or a guarantee that every logger will redact the value. Never log raw credentials. The example contains only a non-secret placeholder. In-memory standalone Cargo example. Expected stdout (not executed): true Common mistake: Assuming sensitive marking makes a token safe to print or transmit without TLS.

Formal Syntax & Structure

rust syntaxrust
HeaderValue::set_sensitive(true)

Working Example

Example Snippetrust
use axum::{Router, body::{Body, to_bytes}, http::{Request, StatusCode}};use tower::ServiceExt;
#[tokio::main(flavor = "current_thread")]async fn main() {    use axum::http::{header, HeaderValue};    let mut placeholder = HeaderValue::from_static("Bearer NOT_A_REAL_TOKEN");    placeholder.set_sensitive(true);    let req = Request::builder().header(header::AUTHORIZATION, placeholder).body(Body::empty()).unwrap();    println!("{}", req.headers()[header::AUTHORIZATION].is_sensitive());}
Rust Reference