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;
55
66use anyhow:: Result ;
77use hyper:: Body ;
8- use regex:: Regex ;
98
109use self :: fs:: { DirHandler , FileHandler } ;
1110use self :: json:: JsonHandler ;
1211use self :: mock:: MockHandler ;
1312use self :: proxy:: ProxyHandler ;
1413use crate :: config;
14+ use crate :: path:: PathRewriter ;
1515
1616#[ derive( Debug ) ]
1717pub struct Handler {
@@ -29,12 +29,6 @@ pub enum HandlerKind {
2929 Mock ( MockHandler ) ,
3030}
3131
32- #[ derive( Debug ) ]
33- pub struct PathRewriter {
34- regex : Regex ,
35- replace : String ,
36- }
37-
3832impl Handler {
3933 pub async fn new ( route : config:: Route ) -> Result < Self > {
4034 let config:: Route {
@@ -45,7 +39,7 @@ impl Handler {
4539 } = route;
4640 let path_rewriter = rewrite_path. map ( |replace| {
4741 let regex = route. to_regex ( ) ;
48- PathRewriter { regex, replace }
42+ PathRewriter :: new ( regex, replace)
4943 } ) ;
5044
5145 let kind = match kind {
@@ -87,9 +81,3 @@ impl Handler {
8781 result
8882 }
8983}
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;
22
33mod config;
44mod handler;
5+ mod path;
56mod response;
67mod route;
78mod 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