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

Lower case request headers #680

Conversation

aaronatbissell
Copy link

Issue #, if available:
Fixes:
#347

Possibly fixes:
#654

Description of changes:
When a request comes in as an API Gateway V1 request, the request headers get passed down as-is. If we are trying to make the req object look like a Node.js HTTP request object, then it should probably include the logic to lower-case all the HTTP headers. Even though we are satisfying the shape of an HTTP object, we aren't satisfying the behavior.

https://nodejs.org/api/http.html#messageheaders

Checklist

  • Tests have been added and are passing
  • Documentation has been updated

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@kibiz0r
Copy link
Contributor

kibiz0r commented Jun 12, 2024

Another possible solution is to change the implementation of ServerlessRequest so that it preserves more of the behavior of its base class http.IncomingMessage.

Right now, it uses Object.assign({ headers }), which overwrites the .headers accessor defined in nodejs.

This would probably work:

Object.assign(this, {
      ip: remoteAddress,
      complete: true,
      httpVersion: '1.1',
      httpVersionMajor: '1',
      httpVersionMinor: '1',
      method,
      rawHeaders: Object.entries(headers).flat(),
      body,
      url
    })

Then it's not the responsibility of the event source to abide by the lowercase rules, and any future changes to the nodejs implementation will be respected without having to duplicate the behavior in this package.

@brettstack
Copy link
Collaborator

@kibiz0r this is a great suggestion. Could you submit a PR for this?

@kibiz0r
Copy link
Contributor

kibiz0r commented Jul 16, 2024

@brettstack Actual implementation turned out to be a little bit different, because the .headers accessor only works right when this[kHeadersCount] is set, and that only gets assigned when the stream handler calls _addHeaderLines()

@brettstack brettstack closed this in 07f20fb Aug 7, 2024
github-actions bot pushed a commit that referenced this pull request Aug 7, 2024
## [4.14.2](v4.14.1...v4.14.2) (2024-08-07)

### Bug Fixes

* leverage native IncomingMessage.headers method ([#684](#684)) ([07f20fb](07f20fb)), closes [#680](#680)
Copy link

github-actions bot commented Aug 7, 2024

🎉 This issue has been resolved in version 4.14.2 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

3 participants