From 1e118ccca94c02496d66b2a6a5573c62195a0242 Mon Sep 17 00:00:00 2001 From: novacrazy Date: Thu, 10 Oct 2024 10:36:22 +0200 Subject: [PATCH] Avoid cloning the uri/path --- axum/src/routing/path_router.rs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/axum/src/routing/path_router.rs b/axum/src/routing/path_router.rs index 32b31025..c3ee0412 100644 --- a/axum/src/routing/path_router.rs +++ b/axum/src/routing/path_router.rs @@ -367,9 +367,9 @@ where } } - let path = req.uri().path().to_owned(); + let (mut parts, body) = req.into_parts(); - match self.node.at(&path) { + match self.node.at(parts.uri.path()) { Ok(match_) => { let id = *match_.value; @@ -378,17 +378,18 @@ where crate::extract::matched_path::set_matched_path_for_request( id, &self.node.route_id_to_path, - req.extensions_mut(), + &mut parts.extensions, ); } - url_params::insert_url_params(req.extensions_mut(), match_.params); + url_params::insert_url_params(&mut parts.extensions, match_.params); let endpoint = self .routes .get(&id) .expect("no route for id. This is a bug in axum. Please file an issue"); + let req = Request::from_parts(parts, body); match endpoint { Endpoint::MethodRouter(method_router) => { Ok(method_router.call_with_state(req, state)) @@ -398,7 +399,7 @@ where } // explicitly handle all variants in case matchit adds // new ones we need to handle differently - Err(MatchError::NotFound) => Err((req, state)), + Err(MatchError::NotFound) => Err((Request::from_parts(parts, body), state)), } }