Skip to content

Commit a9ef9e7

Browse files
committed
feat(request-id): Add request-id constructor
1 parent e2b05bf commit a9ef9e7

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

tower-http/src/request_id.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,7 @@ use tower_layer::Layer;
181181
use tower_service::Service;
182182
use uuid::Uuid;
183183

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

186187
/// Trait for producing [`RequestId`]s.
@@ -241,6 +242,14 @@ impl<M> SetRequestIdLayer<M> {
241242
}
242243
}
243244

245+
/// Create a new `SetRequestIdLayer` that uses `request-id` as the header name.
246+
pub fn request_id(make_request_id: M) -> Self
247+
where
248+
M: MakeRequestId,
249+
{
250+
SetRequestIdLayer::new(REQUEST_ID, make_request_id)
251+
}
252+
244253
/// Create a new `SetRequestIdLayer` that uses `x-request-id` as the header name.
245254
pub fn x_request_id(make_request_id: M) -> Self
246255
where
@@ -294,6 +303,14 @@ impl<S, M> SetRequestId<S, M> {
294303
}
295304
}
296305

306+
/// Create a new `SetRequestId` that uses `request-id` as the header name.
307+
pub fn request_id(inner: S, make_request_id: M) -> Self
308+
where
309+
M: MakeRequestId,
310+
{
311+
Self::new(inner, REQUEST_ID, make_request_id)
312+
}
313+
297314
/// Create a new `SetRequestId` that uses `x-request-id` as the header name.
298315
pub fn x_request_id(inner: S, make_request_id: M) -> Self
299316
where
@@ -359,6 +376,11 @@ impl PropagateRequestIdLayer {
359376
PropagateRequestIdLayer { header_name }
360377
}
361378

379+
/// Create a new `PropagateRequestIdLayer` that uses `request-id` as the header name.
380+
pub fn request_id() -> Self {
381+
Self::new(REQUEST_ID)
382+
}
383+
362384
/// Create a new `PropagateRequestIdLayer` that uses `x-request-id` as the header name.
363385
pub fn x_request_id() -> Self {
364386
Self::new(X_REQUEST_ID)

0 commit comments

Comments
 (0)