File tree Expand file tree Collapse file tree 3 files changed +20
-14
lines changed Expand file tree Collapse file tree 3 files changed +20
-14
lines changed Original file line number Diff line number Diff line change @@ -5,13 +5,13 @@ mod proxy;
5
5
6
6
use anyhow:: Result ;
7
7
use hyper:: Body ;
8
- use regex:: Regex ;
9
8
10
9
use self :: fs:: { DirHandler , FileHandler } ;
11
10
use self :: json:: JsonHandler ;
12
11
use self :: mock:: MockHandler ;
13
12
use self :: proxy:: ProxyHandler ;
14
13
use crate :: config;
14
+ use crate :: path:: PathRewriter ;
15
15
16
16
#[ derive( Debug ) ]
17
17
pub struct Handler {
@@ -29,12 +29,6 @@ pub enum HandlerKind {
29
29
Mock ( MockHandler ) ,
30
30
}
31
31
32
- #[ derive( Debug ) ]
33
- pub struct PathRewriter {
34
- regex : Regex ,
35
- replace : String ,
36
- }
37
-
38
32
impl Handler {
39
33
pub async fn new ( route : config:: Route ) -> Result < Self > {
40
34
let config:: Route {
@@ -45,7 +39,7 @@ impl Handler {
45
39
} = route;
46
40
let path_rewriter = rewrite_path. map ( |replace| {
47
41
let regex = route. to_regex ( ) ;
48
- PathRewriter { regex, replace }
42
+ PathRewriter :: new ( regex, replace)
49
43
} ) ;
50
44
51
45
let kind = match kind {
@@ -87,9 +81,3 @@ impl Handler {
87
81
result
88
82
}
89
83
}
90
-
91
- impl PathRewriter {
92
- fn rewrite < ' a > ( & self , path : & ' a str ) -> String {
93
- self . regex . replace ( path, self . replace . as_str ( ) ) . into_owned ( )
94
- }
95
- }
Original file line number Diff line number Diff line change @@ -2,6 +2,7 @@ use structopt::StructOpt;
2
2
3
3
mod config;
4
4
mod handler;
5
+ mod path;
5
6
mod response;
6
7
mod route;
7
8
mod server;
Original file line number Diff line number Diff line change
1
+ use regex:: Regex ;
2
+
3
+ #[ derive( Debug ) ]
4
+ pub struct PathRewriter {
5
+ regex : Regex ,
6
+ replace : String ,
7
+ }
8
+
9
+ impl PathRewriter {
10
+ pub fn new ( regex : Regex , replace : String ) -> Self {
11
+ PathRewriter { regex, replace }
12
+ }
13
+
14
+ pub fn rewrite < ' a > ( & self , path : & ' a str ) -> String {
15
+ self . regex . replace ( path, self . replace . as_str ( ) ) . into_owned ( )
16
+ }
17
+ }
You can’t perform that action at this time.
0 commit comments