File tree 2 files changed +8
-5
lines changed
2 files changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,7 @@ use crate::util::request_header;
7
7
use conduit:: { header, RequestExt , StatusCode } ;
8
8
use conduit_cookie:: RequestSession ;
9
9
10
+ use crate :: middleware:: normalize_path:: OriginalPath ;
10
11
use crate :: middleware:: response_timing:: ResponseTime ;
11
12
use std:: fmt:: { self , Display , Formatter } ;
12
13
@@ -15,13 +16,8 @@ const SLOW_REQUEST_THRESHOLD_MS: u64 = 1000;
15
16
#[ derive( Default ) ]
16
17
pub ( super ) struct LogRequests ( ) ;
17
18
18
- struct OriginalPath ( String ) ;
19
-
20
19
impl Middleware for LogRequests {
21
20
fn before ( & self , req : & mut dyn RequestExt ) -> BeforeResult {
22
- let path = OriginalPath ( req. path ( ) . to_string ( ) ) ;
23
- req. mut_extensions ( ) . insert ( path) ;
24
-
25
21
if let Some ( request_id) = req
26
22
. headers ( )
27
23
. get ( "x-request-id" )
Original file line number Diff line number Diff line change @@ -4,6 +4,8 @@ use super::prelude::*;
4
4
5
5
use std:: path:: { Component , Path , PathBuf } ;
6
6
7
+ pub struct OriginalPath ( pub String ) ;
8
+
7
9
pub struct NormalizePath ;
8
10
9
11
impl Middleware for NormalizePath {
@@ -14,6 +16,8 @@ impl Middleware for NormalizePath {
14
16
return Ok ( ( ) ) ;
15
17
}
16
18
19
+ let original_path = OriginalPath ( path. to_string ( ) ) ;
20
+
17
21
let path = Path :: new ( path)
18
22
. components ( )
19
23
. fold (
@@ -40,7 +44,10 @@ impl Middleware for NormalizePath {
40
44
. to_string ( ) ; // non-Unicode is replaced with U+FFFD REPLACEMENT CHARACTER
41
45
42
46
add_custom_metadata ( req, "normalized_path" , path. clone ( ) ) ;
47
+
43
48
* req. path_mut ( ) = path;
49
+ req. mut_extensions ( ) . insert ( original_path) ;
50
+
44
51
Ok ( ( ) )
45
52
}
46
53
}
You can’t perform that action at this time.
0 commit comments