Skip to content

Commit b2fa1ed

Browse files
committed
forward query parameters to application process
1 parent 70f880f commit b2fa1ed

File tree

3 files changed

+22
-2
lines changed

3 files changed

+22
-2
lines changed

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ once_cell = "1.7.2"
2020
futures = "0.3.16"
2121
signal-hook = "0.3.9"
2222
signal-hook-tokio = { version = "0.3.0", features = ["futures-v0_3"] }
23+
url = "2.1.1"
2324

2425
[features]
2526
# Force openssl-sys to staticly link in the openssl library. Necessary when

src/main.rs

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use http::HeaderMap;
66
use lambda_http::{
77
handler,
88
lambda_runtime::{self, Context},
9-
Body, IntoResponse, Request, Response,
9+
Body, IntoResponse, Request, RequestExt, Response,
1010
};
1111
use log::*;
1212
use nix::sys::signal::{kill, Signal};
@@ -22,6 +22,7 @@ use std::thread;
2222
use std::time::{Duration, Instant};
2323
use tokio_retry::strategy::FixedInterval;
2424
use tokio_retry::Retry;
25+
use url::form_urlencoded::Serializer;
2526

2627
type Error = Box<dyn std::error::Error + Send + Sync + 'static>;
2728
static 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

Comments
 (0)