Skip to content

Conversation

@usualoma
Copy link
Member

fixes #3920

  • header key is case-insensitive
  • delete header if value is null or undefined

The author should do the following, if applicable

  • Add tests
  • Run tests
  • bun run format:fix && bun run lint:fix to format the code

* header key is case-insensitive
* delete header if value is null or undefined
@codecov
Copy link

codecov bot commented Feb 16, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 91.29%. Comparing base (e7fbc3e) to head (b2ba75f).
Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3922      +/-   ##
==========================================
- Coverage   91.31%   91.29%   -0.03%     
==========================================
  Files         168      168              
  Lines       10673    10773     +100     
  Branches     3167     3075      -92     
==========================================
+ Hits         9746     9835      +89     
- Misses        926      937      +11     
  Partials        1        1              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@usualoma
Copy link
Member Author

Hi @BarryThePenguin. Thank you very much for the report. I appreciate it.

I think you're also thinking about performance in #3921, but I'd like to consider that in a separate PR. I'd like to fix the problem of not being overwritten correctly in this PR, but what do you think?

@usualoma
Copy link
Member Author

@yusukebe
Would you please review this?

Copy link
Contributor

@BarryThePenguin BarryThePenguin left a comment

Choose a reason for hiding this comment

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

I think you're also thinking about performance in #3921, but I'd like to consider that in a separate PR. I'd like to fix the problem of not being overwritten correctly in this PR, but what do you think?

Sounds good 👍🏻

I was having a hard time keeping the PR focused. This PR solves the immediate issue without changing anything else

Comment on lines +55 to +56
Array.isArray(requestInit.headers) ||
requestInit.headers instanceof Headers
Copy link
Contributor

Choose a reason for hiding this comment

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

This makes sense 👍🏻

By excluding type Headers | string[][], only type Record<string, string | undefined> can be used to remove specific headers from a request.

I think it makes the API more complicated, but the behaviour is clearly documented, so it should be fine.

One alternative would be dropping type Headers | string[][], but that might make the API too restrictive 🤔

// delete header if value is null or undefined
headers.delete(key)
} else {
headers.set(key, value)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this is the least surprising choice 👍🏻 Using Headers#append was confusing things for me

@usualoma
Copy link
Member Author

@BarryThePenguin Thank you for your comment!

As you pointed out, the proxy helper behaves as follows.

only type Record<string, string | undefined> can be used to remove specific headers from a request.

This is precisely what is intended, as it is ideal for the pattern described in the documentation: ' to allow for easy removal or overwriting in a declarative way using ...c.req.header()’.

https://hono.dev/docs/helpers/proxy

If type Headers | string[][] is passed, it is assumed that the code is not written in a simple declarative way like ...c.req.header(). In such cases, I think we can assume that the user is deliberately setting up a complex configuration, and we should not perform any modifications to headers.

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
Copy link
Member

@usualoma @BarryThePenguin Thank you both! Looks good. Merging.

@yusukebe yusukebe merged commit 0c405b9 into honojs:main Feb 16, 2025
16 checks passed
@EdamAme-x EdamAme-x mentioned this pull request Feb 19, 2025
4 tasks
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.

helper/proxy not removing undefined headers from ProxyRequestInit

3 participants