Skip to content

Commit e2b05bf

Browse files
authored
chore(request-id): Change X_REQUEST_ID constant type to HeaderName (#551)
1 parent 711a86d commit e2b05bf

File tree

2 files changed

+7
-14
lines changed

2 files changed

+7
-14
lines changed

tower-http/src/builder.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,7 @@ pub trait ServiceBuilderExt<L>: crate::sealed::Sealed<L> + Sized {
302302
where
303303
M: crate::request_id::MakeRequestId,
304304
{
305-
self.set_request_id(
306-
HeaderName::from_static(crate::request_id::X_REQUEST_ID),
307-
make_request_id,
308-
)
305+
self.set_request_id(crate::request_id::X_REQUEST_ID, make_request_id)
309306
}
310307

311308
/// Propgate request ids from requests to responses.
@@ -328,7 +325,7 @@ pub trait ServiceBuilderExt<L>: crate::sealed::Sealed<L> + Sized {
328325
fn propagate_x_request_id(
329326
self,
330327
) -> ServiceBuilder<Stack<crate::request_id::PropagateRequestIdLayer, L>> {
331-
self.propagate_request_id(HeaderName::from_static(crate::request_id::X_REQUEST_ID))
328+
self.propagate_request_id(crate::request_id::X_REQUEST_ID)
332329
}
333330

334331
/// Catch panics and convert them into `500 Internal Server` responses.

tower-http/src/request_id.rs

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

184-
pub(crate) const X_REQUEST_ID: &str = "x-request-id";
184+
pub(crate) const X_REQUEST_ID: HeaderName = HeaderName::from_static("x-request-id");
185185

186186
/// Trait for producing [`RequestId`]s.
187187
///
@@ -246,7 +246,7 @@ impl<M> SetRequestIdLayer<M> {
246246
where
247247
M: MakeRequestId,
248248
{
249-
SetRequestIdLayer::new(HeaderName::from_static(X_REQUEST_ID), make_request_id)
249+
SetRequestIdLayer::new(X_REQUEST_ID, make_request_id)
250250
}
251251
}
252252

@@ -299,11 +299,7 @@ impl<S, M> SetRequestId<S, M> {
299299
where
300300
M: MakeRequestId,
301301
{
302-
Self::new(
303-
inner,
304-
HeaderName::from_static(X_REQUEST_ID),
305-
make_request_id,
306-
)
302+
Self::new(inner, X_REQUEST_ID, make_request_id)
307303
}
308304

309305
define_inner_service_accessors!();
@@ -365,7 +361,7 @@ impl PropagateRequestIdLayer {
365361

366362
/// Create a new `PropagateRequestIdLayer` that uses `x-request-id` as the header name.
367363
pub fn x_request_id() -> Self {
368-
Self::new(HeaderName::from_static(X_REQUEST_ID))
364+
Self::new(X_REQUEST_ID)
369365
}
370366
}
371367

@@ -397,7 +393,7 @@ impl<S> PropagateRequestId<S> {
397393

398394
/// Create a new `PropagateRequestId` that uses `x-request-id` as the header name.
399395
pub fn x_request_id(inner: S) -> Self {
400-
Self::new(inner, HeaderName::from_static(X_REQUEST_ID))
396+
Self::new(inner, X_REQUEST_ID)
401397
}
402398

403399
define_inner_service_accessors!();

0 commit comments

Comments
 (0)