fix: avoid duplicating already set headers
fix #2550
Description
This pull request avoids duplicating already set headers; this was happening because API Gateway V1 event has "multiValueHeaders" for headers with multiple values.
Currently, Hono AWS Lambda adapter appends any value from these "multiValueHeaders" in the current Header instance. This leads to duplicated values when a key is already defined.
How
- Added a condition to only append a value from "multiValueHeaders" when the current key is not already defined or the current value is not already included;
- added unit tests for the createRequest method from EventProcessor to make sure that the Request is adapted correctly, headers are not duplicated and to avoid future regressions;
Tests are following the arrange / act / assert pattern.
getProcessorfunction was exported for unit testing purposes;- Added a comment because the conditions became a little complex.
References
https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-develop-integrations-lambda.html
Author should do the followings, if applicable
- [x] Add tests
- [x] Run tests
- [x]
bun denoifyto generate files for Deno
Extra
Thanks to @jean-leonco that found the bug in @BemteviSeguros API, @kbrandwijk that opened the issue and @ShaneYu that suggested the idea of the fix.
Please let me know if this aligns with the library goals and if the code follows the repository recommendations.
Thanks in advance.
Thanks @Amorim33 !
@watany-dev Could you review this?
I have tried to fix the problem at hand for a short time, but it appears that the header rewrite does not work if I just change the createRequest. In fact, I can see that the test is still failing with this fix.
Hello @watany-dev!
Sorry for this, I didn't realize that tests were not passing when running test:all.
This was happening because of other LambdaEvent related global definitions, the "content-type" header was missing in my test. Just fixed it!
Now, I believe that the tests are running properly and headers are not getting duplicated anymore.
May you please, run the workflow one more time?
Hi @Amorim33
Thanks! Can you run bun run format:fix && bun run lint:fix to format the code?
Sure, thank you @yusukebe !
@Amorim33
Thanks! I'll merge this now.