Module sensitive_headers

Source
Available on crate feature sensitive-headers only.
Expand description

Middlewares that mark headers as sensitive.

§Example

use tower_async_http::sensitive_headers::SetSensitiveHeadersLayer;
use tower_async::{Service, ServiceExt, ServiceBuilder, service_fn};
use http::{Request, Response, header::AUTHORIZATION};
use http_body_util::Full;
use bytes::Bytes;
use std::{iter::once, convert::Infallible};

async fn handle(req: Request<Full<Bytes>>) -> Result<Response<Full<Bytes>>, Infallible> {
    // ...
}

let mut service = ServiceBuilder::new()
    // Mark the `Authorization` header as sensitive so it doesn't show in logs
    //
    // `SetSensitiveHeadersLayer` will mark the header as sensitive on both the
    // request and response.
    //
    // The middleware is constructed from an iterator of headers to easily mark
    // multiple headers at once.
    .layer(SetSensitiveHeadersLayer::new(once(AUTHORIZATION)))
    .service(service_fn(handle));

// Call the service.
let response = service
    .call(Request::new(Full::default()))
    .await?;

Structs§

SetSensitiveHeadersLayer
Mark headers as sensitive on both requests and responses.
SetSensitiveRequestHeaders
Mark request headers as sensitive.
SetSensitiveRequestHeadersLayer
Mark request headers as sensitive.
SetSensitiveResponseHeaders
Mark response headers as sensitive.
SetSensitiveResponseHeadersLayer
Mark response headers as sensitive.

Type Aliases§

SetSensitiveHeaders
Mark headers as sensitive on both requests and responses.