@@ -6,7 +6,7 @@ use http::HeaderMap;
66use lambda_http:: {
77 handler,
88 lambda_runtime:: { self , Context } ,
9- Body , IntoResponse , Request , Response ,
9+ Body , IntoResponse , Request , RequestExt , Response ,
1010} ;
1111use log:: * ;
1212use nix:: sys:: signal:: { kill, Signal } ;
@@ -22,6 +22,7 @@ use std::thread;
2222use std:: time:: { Duration , Instant } ;
2323use tokio_retry:: strategy:: FixedInterval ;
2424use tokio_retry:: Retry ;
25+ use url:: form_urlencoded:: Serializer ;
2526
2627type Error = Box < dyn std:: error:: Error + Send + Sync + ' static > ;
2728static HTTP_CLIENT : OnceCell < Client > = OnceCell :: new ( ) ;
@@ -144,8 +145,25 @@ async fn http_proxy_handler(event: Request, _: Context) -> Result<impl IntoRespo
144145 "http://127.0.0.1:{}" ,
145146 env:: var( "PORT" ) . unwrap_or_else( |_| "8080" . to_string( ) )
146147 ) ;
148+ let query_params = event. query_string_parameters ( ) ;
149+ debug ! ( "query_params are {:#?}" , query_params) ;
150+
147151 let ( parts, body) = event. into_parts ( ) ;
148- let app_url = app_host + parts. uri . path_and_query ( ) . unwrap ( ) . as_str ( ) ;
152+ let mut app_url = app_host + parts. uri . path ( ) ;
153+
154+ // append query parameters to app_url
155+ if !query_params. is_empty ( ) {
156+ app_url. push ( '?' ) ;
157+ let mut serializer = Serializer :: new ( & mut app_url) ;
158+ for ( key, _) in query_params. iter ( ) {
159+ for value in query_params. get_all ( key) . unwrap ( ) . iter ( ) {
160+ serializer. append_pair ( key, value) ;
161+ }
162+ }
163+ serializer. finish ( ) ;
164+ }
165+ debug ! ( "app_url is {:#?}" , app_url) ;
166+
149167 let app_response = HTTP_CLIENT
150168 . get ( )
151169 . unwrap ( )
0 commit comments