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

Optimize header toLowerCasing #310

Merged
merged 2 commits into from
Apr 10, 2024
Merged

Conversation

kanongil
Copy link
Contributor

All requests currently include a number of calls to string toLowerCase() on header names. Especially if there are any user provided headers, where each provided header name is lowercased at 2 - 4 times.

This PR removes the need to lowercase when no headers are provided, and reduces it to a single time for each name when they are provided.

Additionally, this also fixes redundant lowercasing in read() where incoming headers would be lowercased, even though they already were by node.

This is a pure refactor, and should have no effect** other than requiring slightly less CPU/memory usage, while being easier to read.

** The behaviour is actually changed for '' values for host and content-type, where they are now considered set. Also for headers with "duplicate" entries, eg. { host: undefined, HOST: 'hello' }, which will detect it as set, where the old logic would not.

@kanongil kanongil added the feature New functionality or improvement label Mar 22, 2024
@Marsup Marsup added this to the 18.0.2 milestone Apr 10, 2024
@Marsup Marsup merged commit 487b6f5 into hapijs:master Apr 10, 2024
12 of 15 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature New functionality or improvement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants