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

Lowercasing headers to match express/node http behavior #33

Closed
naz opened this issue Feb 15, 2022 · 1 comment · Fixed by #34
Closed

Lowercasing headers to match express/node http behavior #33

naz opened this issue Feb 15, 2022 · 1 comment · Fixed by #34
Labels

Comments

@naz
Copy link
Contributor

naz commented Feb 15, 2022

refs #33 (issue in the upstream dependency)

Node's native http module lowercases incoming headers in the request object (reference). The lowrcasing does not happen when using reqresnext library causing behavior different to production. For example when a miXed-caSe-header: some_value is passed in with an incoming HTTP request, the req['mixed-case-header'] is undefined.

For reference this is how the node-mocks-http, referenced in this project's readme, solves a very similar issue:

mockRequest.headers = options.headers ? utils.convertKeysToLowerCase(options.headers) : {};

And excerpt from utils lib:

module.exports.convertKeysToLowerCase = function(map) {
    var newMap = {};
    for(var key in map) {
        newMap[key.toLowerCase()] = map[key];
    }
    return newMap;
};

I think a correct solution here would be setting lowercased headers to fully mimic express' behavior.

naz added a commit to naz/reqresnext that referenced this issue Feb 15, 2022
refs antongolub#33

- Adds utility that will help mimicing lowercasing of headers like it's done in express' Request object
- Code heavily inspired by https://github.com/howardabrams/node-mocks-http/blob/a0ad193459c102069a9b7de386f16ebf59cab6e0/lib/utils.js#L3-L9
naz added a commit to naz/reqresnext that referenced this issue Feb 15, 2022
closes antongolub#33

- Makes sure incoming header options are always lowercased. This behavior would be the same as in original express request.
naz added a commit to naz/framework that referenced this issue Feb 15, 2022
refs https://github.com/TryGhost/Toolbox/issues/209
refs antongolub/reqresnext#33

- This test should start passing once the upstream dependency (reqresnext) has the referenced issue fixed
naz added a commit to naz/framework that referenced this issue Feb 15, 2022
refs https://github.com/TryGhost/Toolbox/issues/209
refs antongolub/reqresnext#33

- This test should start passing once the upstream dependency (reqresnext) has the referenced issue fixed
naz added a commit to naz/framework that referenced this issue Feb 15, 2022
refs https://github.com/TryGhost/Toolbox/issues/209
refs antongolub/reqresnext#33

- All request headers should be lowercased to match the default behavior in express and node's http module. These patches should be removed once the upstream issue is solved
naz added a commit to TryGhost/framework that referenced this issue Feb 15, 2022
refs https://github.com/TryGhost/Toolbox/issues/209
refs antongolub/reqresnext#33

- This test should start passing once the upstream dependency (reqresnext) has the referenced issue fixed
naz added a commit to TryGhost/framework that referenced this issue Feb 15, 2022
refs https://github.com/TryGhost/Toolbox/issues/209
refs antongolub/reqresnext#33

- All request headers should be lowercased to match the default behavior in express and node's http module. These patches should be removed once the upstream issue is solved
antongolub pushed a commit that referenced this issue Feb 15, 2022
refs #33

- Adds utility that will help mimicing lowercasing of headers like it's done in express' Request object
- Code heavily inspired by https://github.com/howardabrams/node-mocks-http/blob/a0ad193459c102069a9b7de386f16ebf59cab6e0/lib/utils.js#L3-L9
antongolub pushed a commit that referenced this issue Feb 15, 2022
closes #33

- Makes sure incoming header options are always lowercased. This behavior would be the same as in original express request.
@antongolub
Copy link
Owner

🎉 This issue has been resolved in version 1.7.0 🎉

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 a pull request may close this issue.

2 participants