1
1
use std:: borrow:: Cow ;
2
2
use std:: collections:: BTreeSet ;
3
+ use std:: ops:: Deref ;
3
4
use std:: sync:: Arc ;
4
5
5
6
use anyhow:: Result ;
@@ -75,11 +76,8 @@ fn create_request_context(req: &Request<Body>, app_ctx: &AppContext) -> RequestC
75
76
let allowed = upstream. allowed_headers ;
76
77
let req_headers = create_allowed_headers ( req. headers ( ) , & allowed) ;
77
78
78
- let allowed = app_ctx. blueprint . server . get_experimental_headers ( ) ;
79
- let experimental_headers = create_allowed_headers ( req. headers ( ) , & allowed) ;
80
- RequestContext :: from ( app_ctx)
81
- . req_headers ( req_headers)
82
- . experimental_headers ( experimental_headers)
79
+ let _allowed = app_ctx. blueprint . server . get_experimental_headers ( ) ;
80
+ RequestContext :: from ( app_ctx) . request_headers ( req_headers)
83
81
}
84
82
85
83
fn update_cache_control_header (
@@ -95,30 +93,25 @@ fn update_cache_control_header(
95
93
response
96
94
}
97
95
98
- fn update_experimental_headers (
99
- response : & mut hyper:: Response < hyper:: Body > ,
100
- app_ctx : & AppContext ,
101
- req_ctx : Arc < RequestContext > ,
102
- ) {
103
- if !app_ctx. blueprint . server . experimental_headers . is_empty ( ) {
104
- response
105
- . headers_mut ( )
106
- . extend ( req_ctx. experimental_headers . clone ( ) ) ;
107
- }
108
- }
109
-
110
96
pub fn update_response_headers (
111
97
resp : & mut hyper:: Response < hyper:: Body > ,
112
- cookie_headers : Option < HeaderMap > ,
98
+ req_ctx : & RequestContext ,
113
99
app_ctx : & AppContext ,
114
100
) {
115
101
if !app_ctx. blueprint . server . response_headers . is_empty ( ) {
102
+ // Add static response headers
116
103
resp. headers_mut ( )
117
104
. extend ( app_ctx. blueprint . server . response_headers . clone ( ) ) ;
118
105
}
119
- if let Some ( cookie_headers) = cookie_headers {
120
- resp. headers_mut ( ) . extend ( cookie_headers) ;
106
+
107
+ // Insert Cookie Headers
108
+ if let Some ( ref cookie_headers) = req_ctx. cookie_headers {
109
+ let cookie_headers = cookie_headers. lock ( ) . unwrap ( ) ;
110
+ resp. headers_mut ( ) . extend ( cookie_headers. deref ( ) . clone ( ) ) ;
121
111
}
112
+
113
+ // Insert Experimental Headers
114
+ req_ctx. extend_x_headers ( resp. headers_mut ( ) ) ;
122
115
}
123
116
124
117
#[ tracing:: instrument( skip_all, fields( otel. name = "graphQL" , otel. kind = ?SpanKind :: Server ) ) ]
@@ -134,15 +127,10 @@ pub async fn graphql_request<T: DeserializeOwned + GraphQLRequestLike>(
134
127
match graphql_request {
135
128
Ok ( request) => {
136
129
let mut response = request. data ( req_ctx. clone ( ) ) . execute ( & app_ctx. schema ) . await ;
137
- let cookie_headers = req_ctx . cookie_headers . clone ( ) ;
130
+
138
131
response = update_cache_control_header ( response, app_ctx, req_ctx. clone ( ) ) ;
139
132
let mut resp = response. to_response ( ) ?;
140
- update_response_headers (
141
- & mut resp,
142
- cookie_headers. map ( |v| v. lock ( ) . unwrap ( ) . clone ( ) ) ,
143
- app_ctx,
144
- ) ;
145
- update_experimental_headers ( & mut resp, app_ctx, req_ctx) ;
133
+ update_response_headers ( & mut resp, & req_ctx, app_ctx) ;
146
134
Ok ( resp)
147
135
}
148
136
Err ( err) => {
@@ -250,15 +238,9 @@ async fn handle_rest_apis(
250
238
. data ( req_ctx. clone ( ) )
251
239
. execute ( & app_ctx. schema )
252
240
. await ;
253
- let cookie_headers = req_ctx. cookie_headers . clone ( ) ;
254
241
response = update_cache_control_header ( response, app_ctx. as_ref ( ) , req_ctx. clone ( ) ) ;
255
242
let mut resp = response. to_rest_response ( ) ?;
256
- update_response_headers (
257
- & mut resp,
258
- cookie_headers. map ( |v| v. lock ( ) . unwrap ( ) . clone ( ) ) ,
259
- app_ctx. as_ref ( ) ,
260
- ) ;
261
- update_experimental_headers ( & mut resp, app_ctx. as_ref ( ) , req_ctx) ;
243
+ update_response_headers ( & mut resp, & req_ctx, & app_ctx) ;
262
244
Ok ( resp)
263
245
}
264
246
. instrument ( span)
0 commit comments