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

feat(core): lower case http headers, based on env variable. Fixes #311 #318

Closed
wants to merge 1 commit into from

Conversation

alexanderbartels
Copy link

PR Type

Lower Case HTTP Headers behind a Feature Flag as discussed in #311

[ ] Bugfix
[x] Feature
[ ] Code style update (formatting, local variables)
[ ] Refactoring (no functional changes, no api changes)
[ ] Build related changes
[ ] CI related changes
[ ] Documentation content changes
[ ] Other... Please describe:

What is the current behavior?

Issue Number: #311

What is the new behavior?

all http headers are lower cased if the env flag is defined.

Does this PR introduce a breaking change?

[ ] Yes
[x] No

Other information

Just a first draft. as the flag is based on the env flag and it seems to be a good idea to cache the value for performance reason i had no idea how to test with and without the flag.
I can continue after some general feedback.

@alexanderbartels
Copy link
Author

Change is only validated using the automated test cases.
I hadn't the time to try the changes in my own project..

@codecov
Copy link

codecov bot commented Feb 9, 2021

Codecov Report

Merging #318 (9a8aa25) into master (cbdffda) will increase coverage by 0.31%.
The diff coverage is 96.51%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #318      +/-   ##
==========================================
+ Coverage   95.41%   95.72%   +0.31%     
==========================================
  Files         157      164       +7     
  Lines        2769     3137     +368     
  Branches      366      431      +65     
==========================================
+ Hits         2642     3003     +361     
- Misses        123      129       +6     
- Partials        4        5       +1     
Impacted Files Coverage Δ
packages/core/src/context/context.hook.ts 100.00% <ø> (ø)
...ackages/core/src/effects/effectsContext.factory.ts 100.00% <ø> (ø)
packages/core/src/logger/logger.interface.ts 100.00% <ø> (ø)
packages/messaging/src/reply/reply.ts 100.00% <ø> (ø)
...rc/transport/strategies/amqp.strategy.interface.ts 81.81% <ø> (ø)
.../testing/src/testBed/http/http.testBed.response.ts 75.00% <40.00%> (-13.24%) ⬇️
packages/core/src/+internal/utils/string.util.ts 92.00% <66.66%> (-8.00%) ⬇️
packages/core/src/+internal/utils/any.util.ts 84.61% <71.42%> (+1.28%) ⬆️
...ore/src/http/response/http.responseBody.factory.ts 80.95% <73.33%> (-19.05%) ⬇️
...ssaging/src/transport/strategies/local.strategy.ts 92.15% <83.33%> (+4.92%) ⬆️
... and 74 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update bcdc101...9a8aa25. Read the comment docs.

@JozefFlakus
Copy link
Member

Thanks for creating this PR. I'll try to check it tomorrow! 🙌

@JozefFlakus JozefFlakus self-requested a review March 4, 2021 08:05
@JozefFlakus JozefFlakus added enhancement New feature or request scope: core Relates to @marblejs/core package labels Mar 4, 2021
@JozefFlakus JozefFlakus added this to the 3.5 milestone Mar 4, 2021
@JozefFlakus JozefFlakus linked an issue Mar 4, 2021 that may be closed by this pull request
@JozefFlakus
Copy link
Member

@alexanderbartels Finally found some time for reviewing it, sorry for the late response. Before I'll dig more into the details, I have one general question. Why do you think it is needed to memoize this operation. Reading from process.env is a straightforward operation since it is just a plain object 🤔

}

// lower case header
const lowerCasedHeaders = {};
Copy link
Member

Choose a reason for hiding this comment

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

I would extract this process to separate function, eg. #normalizeHeaders - then you can use simple ternary check. If we care here about the performance impact then it can stay as it is, but if not it would be better to use reduce instead of forEach. In typical case the total number of outgoing headers won't reach more than 10.

@alexanderbartels
Copy link
Author

alexanderbartels commented Mar 5, 2021

I have one general question. Why do you think it is needed to memoize this operation. Reading from process.env is a straightforward operation since it is just a plain object 🤔

not sure if its still a problem but here are some references:
https://stackoverflow.com/questions/51138302/is-process-env-node-env-still-slow-in-node-8

cite from https://expressjs.com/en/advanced/best-practice-performance.html

If you need to write environment-specific code, you can check the value of NODE_ENV with process.env.NODE_ENV. Be aware that checking the value of any environment variable incurs a performance penalty, and so should be done sparingly.

and from node issues: nodejs/node#3104
issue was closed with this comment:

Doesn't seem worthwhile. Closing, please cache it yourself if need be. :)

As we hope to get a lot of traffic it might be still a good idea to cache it. But to be really sure if it is still an issue, a performance test would be needed.

@JozefFlakus
Copy link
Member

@alexanderbartels Ok, you convinced me! 🙃

@JozefFlakus
Copy link
Member

@alexanderbartels regarding testing - you can write simple integration/E2E scenarios directly inside @integration module. Do you need more guidance here?

@JozefFlakus JozefFlakus modified the milestones: 3.5, 4.0 Jun 16, 2021
@JozefFlakus
Copy link
Member

@alexanderbartels any updates? If not I'll take it over. I'm planning to introduce it in next major version 4.0

@JozefFlakus JozefFlakus changed the base branch from master to next July 15, 2021 06:59
@JozefFlakus JozefFlakus force-pushed the next branch 3 times, most recently from 1e2fc60 to bd23088 Compare August 9, 2021 10:18
@JozefFlakus
Copy link
Member

JozefFlakus commented Aug 9, 2021

@alexanderbartels could you sync your PR with next branch? I really would like to include this improvement with the upcoming major release but for that I need to have it up-to date. You can also add some additional permissions to your already existing PR in case I would like to take over the work.

https://docs.github.com/en/github/collaborating-with-pull-requests/working-with-forks/allowing-changes-to-a-pull-request-branch-created-from-a-fork

@JozefFlakus
Copy link
Member

Duplicates: #349

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request scope: core Relates to @marblejs/core package
Projects
None yet
Development

Successfully merging this pull request may close these issues.

HTTP Header with case-insensitive header names
3 participants