File tree 2 files changed +8
-8
lines changed 2 files changed +8
-8
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:: request_timing:: ResponseTime ;
11
12
use std:: fmt:: { self , Display , Formatter } ;
12
13
@@ -15,15 +16,7 @@ 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
- fn before ( & self , req : & mut dyn RequestExt ) -> BeforeResult {
22
- let path = OriginalPath ( req. path ( ) . to_string ( ) ) ;
23
- req. mut_extensions ( ) . insert ( path) ;
24
- Ok ( ( ) )
25
- }
26
-
27
20
fn after ( & self , req : & mut dyn RequestExt , res : AfterResult ) -> AfterResult {
28
21
let response_time = req. extensions ( ) . find :: < ResponseTime > ( ) . unwrap ( ) ;
29
22
Original file line number Diff line number Diff line change @@ -4,12 +4,18 @@ 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 {
10
12
fn before ( & self , req : & mut dyn RequestExt ) -> BeforeResult {
11
13
let path = req. path ( ) ;
14
+ let original_path = OriginalPath ( path. to_string ( ) ) ;
15
+
12
16
if !( path. contains ( "//" ) || path. contains ( "/." ) ) {
17
+ req. mut_extensions ( ) . insert ( original_path) ;
18
+
13
19
// Avoid allocations if rewriting is unnecessary
14
20
return Ok ( ( ) ) ;
15
21
}
@@ -40,6 +46,7 @@ impl Middleware for NormalizePath {
40
46
. to_string ( ) ; // non-Unicode is replaced with U+FFFD REPLACEMENT CHARACTER
41
47
42
48
add_custom_metadata ( req, "normalized_path" , path. clone ( ) ) ;
49
+ req. mut_extensions ( ) . insert ( original_path) ;
43
50
* req. path_mut ( ) = path;
44
51
Ok ( ( ) )
45
52
}
You can’t perform that action at this time.
0 commit comments