feat: add SetResolver and SetHosts for custom DNS (#169) - #516
Open
ManuelReschke wants to merge 1 commit into
Open
feat: add SetResolver and SetHosts for custom DNS (#169)#516ManuelReschke wants to merge 1 commit into
ManuelReschke wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Add SetResolver and SetHosts for custom DNS on HTTP/1 and HTTP/2
Fixes #169.
Closes #168 (discussion).
Summary
Adds a simple way to customize DNS resolution for HTTP/1 and HTTP/2, addressing long DNS timeouts when crawling with a known host list.
Client.SetResolver(*net.Resolver)— use a customnet.Resolver(e.g. a specific DNS server) viaSetDial+net.Dialer.Client.SetHosts(map[string]string)— static hostname→IP mapping (hosts-file style). Unlisted hostnames fail immediately with"no such host"and do not hit the system resolver.SetResolver,SetHosts.DialContextis set, the HTTP/2 transport uses it for the underlying TCP dial (includingEnableForceHTTP2), with TLS handshake timeout/trace handling aligned to HTTP/1addTLS.Motivation
From discussion #168: crawlers that hit many domains pay for system DNS timeouts on dead hosts. A custom resolver or hosts map that can return
NOHOSTquickly covers the common case.SetDialalready allowed this, but a dedicated API is clearer and documents the intended pattern.API
Notes:
SetDial). HTTP/3 is unchanged.https://1.2.3.4/) skip the map and dial directly.SetDialTLSstill bypasses this dialer for HTTPS when set.SetDial,SetResolver,SetHosts, andSetUnixSocketreplace each other (last call wins).Tests
SetResolver: IP URL works with a broken custom resolver; hostname fails with that resolver’s error.SetHosts: successful HTTP/1 and forced HTTP/2 via mapped hostname."no such host".SetDialreplaces hosts dialer.Validation: