Skip to content

Commit bb34300

Browse files
authored
Use raw_query_string to populate QueryStringParameters (#483)
API GW v2 is not compatible with the whatgw specification. Using the raw query string makes the request behave closer to the standard. Signed-off-by: David Calavera <[email protected]>
1 parent 22f3941 commit bb34300

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lambda-http/src/request.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,17 @@ fn into_api_gateway_v2_request(ag: ApiGatewayV2httpRequest) -> http::Request<Bod
6363
let http_method = ag.request_context.http.method.clone();
6464
let raw_path = ag.raw_path.unwrap_or_default();
6565

66+
// don't use the query_string_parameters from API GW v2 to
67+
// populate the QueryStringParameters extension because
68+
// the value is not compatible with the whatgw specification.
69+
// See: https://github.com/awslabs/aws-lambda-rust-runtime/issues/470
70+
// See: https://url.spec.whatwg.org/#urlencoded-parsing
71+
let query_string_parameters = if let Some(query) = &ag.raw_query_string {
72+
query.parse().unwrap() // this is Infallible
73+
} else {
74+
ag.query_string_parameters
75+
};
76+
6677
let builder = http::Request::builder()
6778
.uri({
6879
let scheme = ag
@@ -87,7 +98,7 @@ fn into_api_gateway_v2_request(ag: ApiGatewayV2httpRequest) -> http::Request<Bod
8798
url
8899
})
89100
.extension(RawHttpPath(raw_path))
90-
.extension(QueryStringParameters(ag.query_string_parameters))
101+
.extension(QueryStringParameters(query_string_parameters))
91102
.extension(PathParameters(QueryMap::from(ag.path_parameters)))
92103
.extension(StageVariables(QueryMap::from(ag.stage_variables)))
93104
.extension(RequestContext::ApiGatewayV2(ag.request_context));

0 commit comments

Comments
 (0)