Skip to content

Commit 2d45197

Browse files
committed
middleware::log_request: Simplify Display for FullPath implementation
1 parent e3d3db4 commit 2d45197

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/middleware/log_request.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,15 @@ struct FullPath<'a>(&'a dyn RequestExt);
166166

167167
impl<'a> Display for FullPath<'a> {
168168
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
169+
let request = self.0;
170+
171+
let original_path = request.extensions().find::<OriginalPath>();
169172
// Unwrap shouldn't panic as no other code has access to the private struct to remove it
170-
write!(
171-
f,
172-
"{}",
173-
self.0.extensions().find::<OriginalPath>().unwrap().0
174-
)?;
175-
if let Some(q_string) = self.0.query_string() {
173+
let path = original_path.map(|p| p.0.as_str()).unwrap();
174+
175+
write!(f, "{}", path)?;
176+
177+
if let Some(q_string) = request.query_string() {
176178
write!(f, "?{}", q_string)?;
177179
}
178180
Ok(())

0 commit comments

Comments
 (0)