honojs / hono

Web framework built on Web Standards
https://hono.dev
MIT License
20.53k stars 595 forks source link

Multivalue query param support on AWS lambda behind apigateway #3482

Open leaumar opened 1 month ago

leaumar commented 1 month ago

What version of Hono are you using?

4.6.3

What runtime/platform is your app running on?

AWS lambda node20

What steps can reproduce the bug?

Having an api gateway that calls a lambda where hono is listening, a request like GET http://.../helloworld?name=foo&name=bar results in our hono handlers only receiving the last multivalue, i.e. "bar" instead of ["foo","bar"] in a validator('query', ...) middleware. We're aware of the difference between ctx.req.query and ctx.req.queries but we don't use either, only ctx.req.valid('query').

We receive the full multivalue if we run the same hono app locally (so only apigateway and lambda are removed). We can also revert our "upgrade" from koa to hono on the current infrastructure (the same lambda config etc, just different js), and then koa gives us the full multivalue. So it seems to us this must be an issue in hono's integration with api gateway, not something wrong in our infrastructure or call.

What is the expected behavior?

validator('query', ...) should receive multivalue query params

What do you see instead?

only a single value is passed

Additional information

We had a glance at the hono code and believe https://github.com/honojs/hono/blob/main/src/adapter/aws-lambda/handler.ts#L285 is the relevant code, where multiValueQueryStringParameters would have to be used somehow.

But when we look at even the latest @types/aws-lambda, APIGatewayProxyEventV2 does not actually seem to have the field, contrary to what we understand from articles like this. Instead APIGatewayProxyEventMultiValueQueryStringParameters is used on APIGatewayProxyEventBase which APIGatewayProxyEventV2WithRequestContext doesn't extend. Our app does use an authorizer in front of our lambda and APIGatewayProxyWithLambdaAuthorizerEvent has multiValueQueryStringParameters, but we're not sure if that helps at all.

We don't really understand the reasoning in AWS' mess of payload types to be able to be more constructive, we never work with them, sorry. Maybe the most reasonable thing is for hono to just if ("multiValueQueryStringParameters" in event) { and parse it like here if true?

Thanks

yusukebe commented 1 month ago

Thanks @leaumar

@watany-dev @exoego @yiss or others. Can anyone handle this?

yiss commented 1 month ago

Thanks @leaumar I'll take look at it. What version of APIGateway are you using? V1 or v2?

leaumar commented 1 month ago

@yiss our api is listed as a REST type so googling actually tells me it's a V1.