@@ -13,8 +13,10 @@ use std::{
1313 time:: Duration ,
1414} ;
1515
16+ use http:: header:: { HeaderName , HeaderValue } ;
1617use http_body:: Body as HttpBody ;
1718use lambda_extension:: Extension ;
19+ use lambda_http:: aws_lambda_events:: serde_json;
1820pub use lambda_http:: Error ;
1921use lambda_http:: { Body , Request , RequestExt , Response } ;
2022use reqwest:: { redirect, Client , Url } ;
@@ -220,6 +222,7 @@ async fn fetch_response(
220222 ready_at_init. store ( true , Ordering :: SeqCst ) ;
221223 }
222224
225+ let request_context = event. request_context ( ) ;
223226 let path = event. raw_http_path ( ) ;
224227 let mut path = path. as_str ( ) ;
225228 let ( parts, body) = event. into_parts ( ) ;
@@ -229,7 +232,13 @@ async fn fetch_response(
229232 path = path. trim_start_matches ( base_path) ;
230233 }
231234
232- let req_headers = parts. headers ;
235+ let mut req_headers = parts. headers ;
236+
237+ // include request context in http header "x-amzn-request-context"
238+ req_headers. append (
239+ HeaderName :: from_static ( "x-amzn-request-context" ) ,
240+ HeaderValue :: from_bytes ( serde_json:: to_string ( & request_context) . unwrap ( ) . as_bytes ( ) ) . unwrap ( ) ,
241+ ) ;
233242
234243 let mut app_url = domain;
235244 app_url. set_path ( path) ;
0 commit comments