Remove useless into_response calls

Route::new applies a `map_response(into_response)` already, so the
service being given to it doesn't have to involve an into_response call
itself.
This commit is contained in:
Jonas Platte
2025-03-28 09:35:21 +01:00
committed by Jonas Platte
parent 0194d1db9a
commit 902a3941b7
2 changed files with 4 additions and 12 deletions
+3 -7
View File
@@ -19,7 +19,7 @@ use std::{
fmt,
task::{Context, Poll},
};
use tower::{service_fn, util::MapResponseLayer};
use tower::service_fn;
use tower_layer::Layer;
use tower_service::Service;
@@ -748,7 +748,7 @@ where
/// requests.
pub fn new() -> Self {
let fallback = Route::new(service_fn(|_: Request| async {
Ok(StatusCode::METHOD_NOT_ALLOWED.into_response())
Ok(StatusCode::METHOD_NOT_ALLOWED)
}));
Self {
@@ -1016,11 +1016,7 @@ where
);
}
let layer_fn = move |svc| {
let svc = layer.layer(svc);
let svc = MapResponseLayer::new(IntoResponse::into_response).layer(svc);
Route::new(svc)
};
let layer_fn = move |svc| Route::new(layer.layer(svc));
self.get = self.get.map(layer_fn.clone());
self.head = self.head.map(layer_fn.clone());
+1 -5
View File
@@ -67,11 +67,7 @@ impl<E> Route<E> {
<L::Service as Service<Request>>::Future: Send + 'static,
NewError: 'static,
{
let layer = (
MapErrLayer::new(Into::into),
MapResponseLayer::new(IntoResponse::into_response),
layer,
);
let layer = (MapErrLayer::new(Into::into), layer);
Route::new(layer.layer(self))
}