You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm running into an issue where URLs with spaces are causing my Lambda function to return server errors on API Gateway.
I'm no expert in URL encoding but I do realise that spaces are unsafe characters and should be avoided at all costs. Unfortunately the product I am building is acting as a sort of redirecting proxy and I am not in full control of the URL structure.
Here is the information needed to reproduce this error:
# Cargo.toml
[package]
name = "http-basic-bug"version = "0.1.0"edition = "2021"
[[bin]]
name = "example"path = "main.rs"
[dependencies]
lambda_http = "0.6.0"lambda_runtime = "0.6.0"tokio = { version = "1", features = ["macros"] }
tracing = { version = "0.1", features = ["log"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt"] }
// main.rsuse lambda_http::{run, service_fn,Body,Error,Request,Response};asyncfnfunction_handler(_event:Request) -> Result<Response<Body>,Error>{// Extract some useful information from the request// Return something that implements IntoResponse.// It will be serialized to the right response event automatically by the runtimelet resp = Response::builder().status(200).header("content-type","text/html").body("Hello AWS Lambda HTTP request".into()).map_err(Box::new)?;Ok(resp)}#[tokio::main]asyncfnmain() -> Result<(),Error>{
tracing_subscriber::fmt().with_max_level(tracing::Level::INFO)// disabling time is handy because CloudWatch will add the ingestion time..without_time().init();run(service_fn(function_handler)).await}#[cfg(test)]mod tests {usesuper::*;#[tokio::test]asyncfntest_no_space(){let input = include_str!("good-request.json");let request = lambda_http::request::from_str(input).expect("failed to create request");let response = function_handler(request).await.expect("failed to handle request");assert_eq!(response.status().as_u16(),200);}#[tokio::test]asyncfntest_with_space(){let input = include_str!("bad-request.json");let request = lambda_http::request::from_str(input).expect("failed to create request");let response = function_handler(request).await.expect("failed to handle request");assert_eq!(response.status().as_u16(),200);}}
Thanks for opening this issue with such clear details. I think we probably need to encode the path before creating the URI for all the events. That should fix the issue, any other ideas are very welcome. Probably in these two places if you want to give it a try:
Comments on closed issues are hard for the maintainers of this repository to see.
If you need more assistance, please open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.
Hi,
I'm running into an issue where URLs with spaces are causing my Lambda function to return server errors on API Gateway.
I'm no expert in URL encoding but I do realise that spaces are unsafe characters and should be avoided at all costs. Unfortunately the product I am building is acting as a sort of redirecting proxy and I am not in full control of the URL structure.
Here is the information needed to reproduce this error:
~ rustc --version rustc 1.61.0 (fe5b13d68 2022-05-18)
Place the following files in the same directory:
good-request.json
bad-request.json
Run the tests
If this is a case of using unsafe characters or you don't feel like this is an issue of
lambda_http
then please close this issue.The text was updated successfully, but these errors were encountered: