Skip to content

Commit 8c6736a

Browse files
committed
middleware::log_request: Move OriginalPath code into NormalizePath middleware
1 parent 179233b commit 8c6736a

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

src/middleware/log_request.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::util::request_header;
77
use conduit::{header, RequestExt, StatusCode};
88
use conduit_cookie::RequestSession;
99

10+
use crate::middleware::normalize_path::OriginalPath;
1011
use crate::middleware::response_timing::ResponseTime;
1112
use std::fmt::{self, Display, Formatter};
1213

@@ -15,13 +16,8 @@ const SLOW_REQUEST_THRESHOLD_MS: u64 = 1000;
1516
#[derive(Default)]
1617
pub(super) struct LogRequests();
1718

18-
struct OriginalPath(String);
19-
2019
impl Middleware for LogRequests {
2120
fn before(&self, req: &mut dyn RequestExt) -> BeforeResult {
22-
let path = OriginalPath(req.path().to_string());
23-
req.mut_extensions().insert(path);
24-
2521
if let Some(request_id) = req
2622
.headers()
2723
.get("x-request-id")

src/middleware/normalize_path.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use super::prelude::*;
44

55
use std::path::{Component, Path, PathBuf};
66

7+
pub struct OriginalPath(pub String);
8+
79
pub struct NormalizePath;
810

911
impl Middleware for NormalizePath {
@@ -14,6 +16,8 @@ impl Middleware for NormalizePath {
1416
return Ok(());
1517
}
1618

19+
let original_path = OriginalPath(path.to_string());
20+
1721
let path = Path::new(path)
1822
.components()
1923
.fold(
@@ -40,7 +44,10 @@ impl Middleware for NormalizePath {
4044
.to_string(); // non-Unicode is replaced with U+FFFD REPLACEMENT CHARACTER
4145

4246
add_custom_metadata(req, "normalized_path", path.clone());
47+
4348
*req.path_mut() = path;
49+
req.mut_extensions().insert(original_path);
50+
4451
Ok(())
4552
}
4653
}

0 commit comments

Comments
 (0)