Skip to content

Commit

Permalink
add: use /etc/resolv.conf for config by default
Browse files Browse the repository at this point in the history
  • Loading branch information
CorentinB committed Sep 25, 2024
1 parent 9d9200a commit 760cc9a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 9 deletions.
9 changes: 5 additions & 4 deletions client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ type HTTPClientSettings struct {
TempDir string
DNSServer string
SkipHTTPStatusCodes []int
DNSServers []string
DedupeOptions DedupeOptions
TCPTimeout time.Duration
TLSHandshakeTimeout time.Duration
DialTimeout time.Duration
ResponseHeaderTimeout time.Duration
DNSResolutionTimeout time.Duration
DialTimeout time.Duration
TLSHandshakeTimeout time.Duration
TCPTimeout time.Duration
MaxReadBeforeTruncate int
DecompressBody bool
FollowRedirects bool
Expand Down Expand Up @@ -169,7 +170,7 @@ func NewWARCWritingHTTPClient(HTTPClientSettings HTTPClientSettings) (httpClient
httpClient.TLSHandshakeTimeout = HTTPClientSettings.TLSHandshakeTimeout

// Configure custom dialer / transport
customDialer, err := newCustomDialer(httpClient, HTTPClientSettings.Proxy, HTTPClientSettings.DialTimeout, HTTPClientSettings.DNSResolutionTimeout, HTTPClientSettings.DNSServer, HTTPClientSettings.DisableIPv4, HTTPClientSettings.DisableIPv6)
customDialer, err := newCustomDialer(httpClient, HTTPClientSettings.Proxy, HTTPClientSettings.DialTimeout, HTTPClientSettings.DNSResolutionTimeout, HTTPClientSettings.DNSServers, HTTPClientSettings.DisableIPv4, HTTPClientSettings.DisableIPv6)
if err != nil {
return nil, err
}
Expand Down
13 changes: 9 additions & 4 deletions dialer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,29 @@ import (
type customDialer struct {
proxyDialer proxy.Dialer
client *CustomHTTPClient
DNSConfig *dns.ClientConfig
DNSClient *dns.Client
net.Dialer
DNSServer string
disableIPv4 bool
disableIPv6 bool
}

func newCustomDialer(httpClient *CustomHTTPClient, proxyURL string, DialTimeout, DNSResolutionTimeout time.Duration, DNSServer string, disableIPv4, disableIPv6 bool) (d *customDialer, err error) {
func newCustomDialer(httpClient *CustomHTTPClient, proxyURL string, DialTimeout, DNSResolutionTimeout time.Duration, DNSServers []string, disableIPv4, disableIPv6 bool) (d *customDialer, err error) {
d = new(customDialer)

d.Timeout = DialTimeout
d.client = httpClient
d.disableIPv4 = disableIPv4
d.disableIPv6 = disableIPv6

d.DNSServer = DNSServer
if DNSServer == "" {
d.DNSServer = "1.1.1.1:53"
d.DNSConfig, err = dns.ClientConfigFromFile("/etc/resolv.conf")
if err != nil {
return nil, err
}

if len(DNSServers) > 0 {
d.DNSConfig.Servers = DNSServers
}

d.DNSClient = &dns.Client{
Expand Down
2 changes: 1 addition & 1 deletion dns.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ func (d *customDialer) resolveDNS(address string) (net.IP, error) {
m := new(dns.Msg)
m.SetQuestion(dns.Fqdn(address), dns.TypeA)

r, _, err := d.DNSClient.Exchange(m, d.DNSServer)
r, _, err := d.DNSClient.Exchange(m, net.JoinHostPort(d.DNSConfig.Servers[0], d.DNSConfig.Port))
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 760cc9a

Please sign in to comment.