File tree Expand file tree Collapse file tree 3 files changed +13
-7
lines changed Expand file tree Collapse file tree 3 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -39,6 +39,8 @@ pub struct Config {
39
39
pub struct Route {
40
40
pub route : route:: Route ,
41
41
pub rewrite_path : Option < String > ,
42
+ #[ serde( with = "http_serde::header_map" , default ) ]
43
+ pub response_headers : http:: HeaderMap ,
42
44
#[ serde( flatten) ]
43
45
pub kind : RouteKind ,
44
46
}
@@ -74,8 +76,6 @@ pub struct JsonRoute {
74
76
pub struct ProxyRoute {
75
77
#[ serde( rename = "url" , with = "http_serde::uri" ) ]
76
78
pub uri : Uri ,
77
- #[ serde( with = "http_serde::header_map" , default ) ]
78
- pub response_headers : http:: HeaderMap ,
79
79
}
80
80
81
81
impl Config {
Original file line number Diff line number Diff line change @@ -15,6 +15,7 @@ use crate::config;
15
15
pub struct Handler {
16
16
kind : HandlerKind ,
17
17
path_rewriter : Option < PathRewriter > ,
18
+ response_headers : http:: HeaderMap ,
18
19
}
19
20
20
21
#[ derive( Debug ) ]
@@ -37,6 +38,7 @@ impl Handler {
37
38
rewrite_path,
38
39
route,
39
40
kind,
41
+ response_headers,
40
42
} = route;
41
43
let path_rewriter = rewrite_path. map ( |replace| {
42
44
let regex = route. to_regex ( ) ;
@@ -53,6 +55,7 @@ impl Handler {
53
55
Ok ( Handler {
54
56
path_rewriter,
55
57
kind,
58
+ response_headers,
56
59
} )
57
60
}
58
61
@@ -65,12 +68,18 @@ impl Handler {
65
68
None => request. uri ( ) . path ( ) . to_owned ( ) ,
66
69
} ;
67
70
68
- match & self . kind {
71
+ let mut result = match & self . kind {
69
72
HandlerKind :: File ( file) => file. handle ( request) . await ,
70
73
HandlerKind :: Dir ( dir) => dir. handle ( request, & path) . await ,
71
74
HandlerKind :: Proxy ( proxy) => proxy. handle ( request, & path) . await ,
72
75
HandlerKind :: Json ( json) => json. handle ( request, & path) . await ,
76
+ } ;
77
+
78
+ if let Ok ( response) = & mut result {
79
+ response. headers_mut ( ) . extend ( self . response_headers . clone ( ) ) ;
73
80
}
81
+
82
+ result
74
83
}
75
84
}
76
85
Original file line number Diff line number Diff line change @@ -52,10 +52,7 @@ impl ProxyHandler {
52
52
log:: debug!( "Forwarding request to `{}`" , request. uri( ) ) ;
53
53
54
54
match self . client . request ( request) . await {
55
- Ok ( mut response) => {
56
- response
57
- . headers_mut ( )
58
- . extend ( self . config . response_headers . clone ( ) ) ;
55
+ Ok ( response) => {
59
56
Ok ( response)
60
57
}
61
58
Err ( err) => {
You can’t perform that action at this time.
0 commit comments