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

Support header filtering for getRequestHeaders #613

Closed
antoinerey opened this issue Jan 9, 2024 · 2 comments
Closed

Support header filtering for getRequestHeaders #613

antoinerey opened this issue Jan 9, 2024 · 2 comments
Labels
enhancement New feature or request

Comments

@antoinerey
Copy link

antoinerey commented Jan 9, 2024

Environment

h3@1.10.0
node@18.18.2

Reproduction

const headers = getRequestHeaders(event, ['host', 'cookie'])

const expected = { 
  host: '...', 
  cookie: '...', 
}

const actual = { 
  host: '...', 
  cookie: '...', 
  'accept-language': '...', 
  'user-agent': '...',
  // ... many more  
}

Describe the bug

When reading the README, the signature of getRequestHeaders looks like this:

getRequestHeaders(event, headers)

I believe the second parameter was originally meant to retrieve only a subset of all request headers, similar to the useRequestHeaders of Nuxt. However, that documented signature does not match the signature of the function implementation itself.

I believe that the original intent was good, and getRequestHeaders should accept a second parameter to pick whatever headers we want to retrieve. In brief, the following code should work as expected:

const headers = getRequestHeaders(event, ['host', 'cookie'])
//    ^? { host: '...', cookie: '...' }

Additional context

I'm open to creating a fix though.

Logs

No response

pi0 added a commit that referenced this issue Jan 16, 2024
@pi0 pi0 changed the title getRequestHeaders (and getHeaders) does not accept a second parameter as documented in the README Support header filtering for getRequestHeaders Jan 16, 2024
@pi0 pi0 added the enhancement New feature or request label Jan 16, 2024
@pi0
Copy link
Member

pi0 commented Feb 24, 2024

Please see reasonings in #620 (comment)

You might want to apply filtering directly on top of this method.

@pi0 pi0 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 24, 2024
@antoinerey
Copy link
Author

Got it. It makes sense. Thanks for the time! 🤗

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants