From f22ca2f82f5d49a6f1ba80b7814dc9cca71ce0a1 Mon Sep 17 00:00:00 2001 From: Sam Date: Tue, 27 Sep 2022 21:03:32 +0000 Subject: [PATCH 1/2] feat(resolvers/HTTPS): add HTTP proxy support --- pkg/resolvers/HTTPS.go | 12 ++++++++++++ pkg/resolvers/docs.go | 4 ++++ 2 files changed, 16 insertions(+) create mode 100644 pkg/resolvers/docs.go diff --git a/pkg/resolvers/HTTPS.go b/pkg/resolvers/HTTPS.go index 79cc2ea..bb896ad 100644 --- a/pkg/resolvers/HTTPS.go +++ b/pkg/resolvers/HTTPS.go @@ -4,6 +4,7 @@ package resolvers import ( "bytes" + "crypto/tls" "fmt" "io" "net/http" @@ -26,6 +27,17 @@ func (resolver *HTTPSResolver) LookUp(msg *dns.Msg) (util.Response, error) { httpR := &http.Client{ Timeout: resolver.opts.Request.Timeout, + Transport: &http.Transport{ + MaxConnsPerHost: 1, + MaxIdleConns: 1, + MaxIdleConnsPerHost: 1, + Proxy: http.ProxyFromEnvironment, + TLSClientConfig: &tls.Config{ + //nolint:gosec // This is intentional if the user requests it + InsecureSkipVerify: resolver.opts.TLSNoVerify, + ServerName: resolver.opts.TLSHost, + }, + }, } buf, err := msg.Pack() diff --git a/pkg/resolvers/docs.go b/pkg/resolvers/docs.go new file mode 100644 index 0000000..cdec9e7 --- /dev/null +++ b/pkg/resolvers/docs.go @@ -0,0 +1,4 @@ +/* +Package resolvers contain the various DNS resolvers to use. +*/ +package resolvers -- 2.45.2 From 937d0826e386d46d811ca3ee3df6d85cf54fbc77 Mon Sep 17 00:00:00 2001 From: Sam Date: Wed, 28 Sep 2022 14:55:00 +0000 Subject: [PATCH 2/2] fix: apply suggested change I like it so I'm keeping it :) --- pkg/resolvers/HTTPS.go | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pkg/resolvers/HTTPS.go b/pkg/resolvers/HTTPS.go index bb896ad..b9994b3 100644 --- a/pkg/resolvers/HTTPS.go +++ b/pkg/resolvers/HTTPS.go @@ -16,7 +16,8 @@ import ( // HTTPSResolver is for DNS-over-HTTPS queries. type HTTPSResolver struct { - opts util.Options + client http.Client + opts util.Options } var _ Resolver = (*HTTPSResolver)(nil) @@ -25,7 +26,7 @@ var _ Resolver = (*HTTPSResolver)(nil) func (resolver *HTTPSResolver) LookUp(msg *dns.Msg) (util.Response, error) { var resp util.Response - httpR := &http.Client{ + resolver.client = http.Client{ Timeout: resolver.opts.Request.Timeout, Transport: &http.Transport{ MaxConnsPerHost: 1, @@ -56,7 +57,7 @@ func (resolver *HTTPSResolver) LookUp(msg *dns.Msg) (util.Response, error) { req.Header.Set("Accept", "application/dns-message") now := time.Now() - res, err := httpR.Do(req) + res, err := resolver.client.Do(req) resp.RTT = time.Since(now) if err != nil { -- 2.45.2