Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions tower-http/src/request_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ use tower_layer::Layer;
use tower_service::Service;
use uuid::Uuid;

pub(crate) const REQUEST_ID: HeaderName = HeaderName::from_static("request-id");
pub(crate) const X_REQUEST_ID: HeaderName = HeaderName::from_static("x-request-id");

/// Trait for producing [`RequestId`]s.
Expand Down Expand Up @@ -241,6 +242,14 @@ impl<M> SetRequestIdLayer<M> {
}
}

/// Create a new `SetRequestIdLayer` that uses `request-id` as the header name.
pub fn request_id(make_request_id: M) -> Self
where
M: MakeRequestId,
{
SetRequestIdLayer::new(REQUEST_ID, make_request_id)
}

/// Create a new `SetRequestIdLayer` that uses `x-request-id` as the header name.
pub fn x_request_id(make_request_id: M) -> Self
where
Expand Down Expand Up @@ -294,6 +303,14 @@ impl<S, M> SetRequestId<S, M> {
}
}

/// Create a new `SetRequestId` that uses `request-id` as the header name.
pub fn request_id(inner: S, make_request_id: M) -> Self
where
M: MakeRequestId,
{
Self::new(inner, REQUEST_ID, make_request_id)
}

/// Create a new `SetRequestId` that uses `x-request-id` as the header name.
pub fn x_request_id(inner: S, make_request_id: M) -> Self
where
Expand Down Expand Up @@ -359,6 +376,11 @@ impl PropagateRequestIdLayer {
PropagateRequestIdLayer { header_name }
}

/// Create a new `PropagateRequestIdLayer` that uses `request-id` as the header name.
pub fn request_id() -> Self {
Self::new(REQUEST_ID)
}

/// Create a new `PropagateRequestIdLayer` that uses `x-request-id` as the header name.
pub fn x_request_id() -> Self {
Self::new(X_REQUEST_ID)
Expand Down