Add lookup option to override dns lookups #1574
Open
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.
The cause of this is that when proxying api requests to a hostname, node will perform a dns query for every single request, which adds unnecessary overhead. While I was investigating I found nodejs/node#5893 and understood that there is no built in dns caching in node and that it seemingly bypasses OS dns cache. Adding a dns cache into
http-proxy
would clearly not be optimal, but by exposing thelookup
option forrequest()
we can customize the dns lookup thathttp-proxy
performs and add our own cache, or inject https://www.npmjs.com/package/dns-lookup-cache or something similiar. (fixes #653)This configuration would also allow to customize the DNS lookup (fixes #1315)
One problem with this is that the
request()
lookup
option is only available in node v12 and later, so using the option when running node 8/10 would not have any effect. shouldn't implode either, but does nothing.