This repository was archived by the owner on May 9, 2020. It is now read-only.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Perks:
caseless
.toLowerCase
for each key only once.Rationale
Cloudscraper currently checks a few different headers using caseless.
cloudscraper/index.js
Lines 157 to 158 in 0d86d22
cloudscraper/index.js
Line 166 in 0d86d22
The following code is used for each

response.caseless.get
method call:https://github.com/request/caseless/blob/98079105e15e04308d1f3becc3e8efab8ddd7f0e/index.js#L27-L36
It's iterating over all the keys, calling
toLowerCase
and then comparing the result each time we check a header. This is inefficient, especially when the headers that we're checking for tend to be the last in the list.i.e.
There are other optimizations we can make to Cloudscraper that involve checking additional headers and would cause even a greater performance penalty if left unchanged.