Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(aws-lambda): avoid duplicating already set headers #2585

Merged
merged 2 commits into from
May 6, 2024

Conversation

Amorim33
Copy link
Contributor

@Amorim33 Amorim33 commented May 1, 2024

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.

  • getProcessor function 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

  • Add tests
  • Run tests
  • bun denoify to 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.

@yusukebe
Copy link
Member

yusukebe commented May 1, 2024

Thanks @Amorim33 !

@watany-dev Could you review this?

@watany-dev
Copy link
Contributor

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.

@Amorim33
Copy link
Contributor Author

Amorim33 commented May 5, 2024

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?

@yusukebe
Copy link
Member

yusukebe commented May 6, 2024

Hi @Amorim33

Thanks! Can you run bun run format:fix && bun run lint:fix to format the code?

@Amorim33 Amorim33 force-pushed the avoid-duplicating-set-headers branch from c8a1f82 to 9e759dd Compare May 6, 2024 18:03
@Amorim33
Copy link
Contributor Author

Amorim33 commented May 6, 2024

Sure, thank you @yusukebe !

Copy link
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@yusukebe yusukebe changed the title fix: avoid duplicating already set headers fix(aws-lambda): avoid duplicating already set headers May 6, 2024
@yusukebe
Copy link
Member

yusukebe commented May 6, 2024

@Amorim33

Thanks! I'll merge this now.

@yusukebe yusukebe merged commit c95e135 into honojs:main May 6, 2024
10 checks passed
nicolewhite pushed a commit to autoblocksai/cli that referenced this pull request May 13, 2024
[![Mend
Renovate](https://app.renovatebot.com/images/banner.svg)](https://renovatebot.com)

This PR contains the following updates:

| Package | Change | Age | Adoption | Passing | Confidence |
|---|---|---|---|---|---|
| [hono](https://hono.dev/) ([source](https://togithub.com/honojs/hono))
| [`4.3.0` ->
`4.3.6`](https://renovatebot.com/diffs/npm/hono/4.3.0/4.3.6) |
[![age](https://developer.mend.io/api/mc/badges/age/npm/hono/4.3.6?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![adoption](https://developer.mend.io/api/mc/badges/adoption/npm/hono/4.3.6?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![passing](https://developer.mend.io/api/mc/badges/compatibility/npm/hono/4.3.0/4.3.6?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|
[![confidence](https://developer.mend.io/api/mc/badges/confidence/npm/hono/4.3.0/4.3.6?slim=true)](https://docs.renovatebot.com/merge-confidence/)
|

---

### Release Notes

<details>
<summary>honojs/hono (hono)</summary>

### [`v4.3.6`](https://togithub.com/honojs/hono/releases/tag/v4.3.6)

[Compare
Source](https://togithub.com/honojs/hono/compare/v4.3.5...v4.3.6)

#### What's Changed

- feat(cache): improved customizability by
[@&#8203;MathurAditya724](https://togithub.com/MathurAditya724) in
[honojs/hono#2652
- fix(utils/body): support multiple `File`s by
[@&#8203;yusukebe](https://togithub.com/yusukebe) in
[honojs/hono#2665

#### New Contributors

- [@&#8203;MathurAditya724](https://togithub.com/MathurAditya724) made
their first contribution in
[honojs/hono#2652

**Full Changelog**:
honojs/hono@v4.3.5...v4.3.6

### [`v4.3.5`](https://togithub.com/honojs/hono/releases/tag/v4.3.5)

[Compare
Source](https://togithub.com/honojs/hono/compare/v4.3.4...v4.3.5)

#### What's Changed

- refactor(context): remove some `any` by
[@&#8203;yusukebe](https://togithub.com/yusukebe) in
[honojs/hono#2658
- feat(hono-base): tweaks `fetch` signature for better compatibility
with `deno serve` by [@&#8203;usualoma](https://togithub.com/usualoma)
in
[honojs/hono#2661
- perf(types): add type annotations by
[@&#8203;yusukebe](https://togithub.com/yusukebe) in
[honojs/hono#2663

**Full Changelog**:
honojs/hono@v4.3.4...v4.3.5

### [`v4.3.4`](https://togithub.com/honojs/hono/releases/tag/v4.3.4)

[Compare
Source](https://togithub.com/honojs/hono/compare/v4.3.3...v4.3.4)

#### What's Changed

- chore: update the pull request template by
[@&#8203;yusukebe](https://togithub.com/yusukebe) in
[honojs/hono#2647
- feat(validator): check for json subtypes in validator by
[@&#8203;ztiromoritz](https://togithub.com/ztiromoritz) in
[honojs/hono#2634
- feat(jsx/dom): support getServerSnapshot in useSyncExternalStore by
[@&#8203;usualoma](https://togithub.com/usualoma) in
[honojs/hono#2646

#### New Contributors

- [@&#8203;ztiromoritz](https://togithub.com/ztiromoritz) made their
first contribution in
[honojs/hono#2634

**Full Changelog**:
honojs/hono@v4.3.3...v4.3.4

### [`v4.3.3`](https://togithub.com/honojs/hono/releases/tag/v4.3.3)

[Compare
Source](https://togithub.com/honojs/hono/compare/v4.3.2...v4.3.3)

#### What's Changed

- fix(types): relax the type of `c.req.param()` by
[@&#8203;yusukebe](https://togithub.com/yusukebe) in
[honojs/hono#2613
- chore(eslint): enable `@typescript-eslint/unbound-method` by
[@&#8203;yusukebe](https://togithub.com/yusukebe) in
[honojs/hono#2622
- fix(factory): support `createFactory()` destruction by
[@&#8203;yusukebe](https://togithub.com/yusukebe) in
[honojs/hono#2623
- fix(aws-lambda): avoid duplicating already set headers by
[@&#8203;Amorim33](https://togithub.com/Amorim33) in
[honojs/hono#2585
- refactor: improve parseBody function and docs by
[@&#8203;mgrithm](https://togithub.com/mgrithm) in
[honojs/hono#2628
- fix(validator): `form` supports multiple values with `foo[]` by
[@&#8203;yusukebe](https://togithub.com/yusukebe) in
[honojs/hono#2639

#### New Contributors

- [@&#8203;Amorim33](https://togithub.com/Amorim33) made their first
contribution in
[honojs/hono#2585

**Full Changelog**:
honojs/hono@v4.3.2...v4.3.3

### [`v4.3.2`](https://togithub.com/honojs/hono/releases/tag/v4.3.2)

[Compare
Source](https://togithub.com/honojs/hono/compare/v4.3.1...v4.3.2)

#### What's Changed

- fix(types): correct inferring when Method has Endponts as Union by
[@&#8203;yusukebe](https://togithub.com/yusukebe) in
[honojs/hono#2610

**Full Changelog**:
honojs/hono@v4.3.1...v4.3.2

### [`v4.3.1`](https://togithub.com/honojs/hono/releases/tag/v4.3.1)

[Compare
Source](https://togithub.com/honojs/hono/compare/v4.3.0...v4.3.1)

#### What's Changed

- fix(types): `ToSchema` compatibility by
[@&#8203;NamesMT](https://togithub.com/NamesMT) in
[honojs/hono#2605

**Full Changelog**:
honojs/hono@v4.3.0...v4.3.1

</details>

---

### Configuration

📅 **Schedule**: Branch creation - "before 4am on Monday" in timezone
America/Chicago, Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you
are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the
rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update
again.

---

- [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check
this box

---

This PR has been generated by [Mend
Renovate](https://www.mend.io/free-developer-tools/renovate/). View
repository job log
[here](https://developer.mend.io/github/autoblocksai/cli).

<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNy4zNDAuMTAiLCJ1cGRhdGVkSW5WZXIiOiIzNy4zNTEuMiIsInRhcmdldEJyYW5jaCI6Im1haW4iLCJsYWJlbHMiOltdfQ==-->

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Regression caused by multiHeaderValue handling on Lambda
3 participants