From eac353cf75a66917a29b15b8a0d6f7c80a8bb08e Mon Sep 17 00:00:00 2001 From: Nate Sales Date: Tue, 19 Dec 2023 22:14:07 -0800 Subject: [PATCH] feat: add http2 flag (#81) --- README.md | 1 + cli/cli.go | 2 +- resolver.go | 1 + transport/http.go | 24 ++++++++++++++++-------- 4 files changed, 19 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 8a0b945..a4763ae 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ Application Options: -p, --odoh-proxy= ODoH proxy --timeout= Query timeout (default: 10s) --pad Set EDNS0 padding + --http2 Use HTTP/2 for DoH --http3 Use HTTP/3 for DoH --id-check Check DNS response ID (default: true) --reuse-conn Reuse connections across queries to the same diff --git a/cli/cli.go b/cli/cli.go index 3fc7406..1d8ca26 100644 --- a/cli/cli.go +++ b/cli/cli.go @@ -24,6 +24,7 @@ type Flags struct { ODoHProxy string `short:"p" long:"odoh-proxy" description:"ODoH proxy"` Timeout time.Duration `long:"timeout" description:"Query timeout" default:"10s"` Pad bool `long:"pad" description:"Set EDNS0 padding"` + HTTP2 bool `long:"http2" description:"Use HTTP/2 for DoH"` HTTP3 bool `long:"http3" description:"Use HTTP/3 for DoH"` IDCheck bool `long:"id-check" description:"Check DNS response ID (default: true)"` ReuseConn bool `long:"reuse-conn" description:"Reuse connections across queries to the same server (default: true)"` @@ -151,7 +152,6 @@ func SetFalseBooleans(opts *Flags, args []string) []string { var remainingArgs []string for _, arg := range args { - if strings.HasSuffix(arg, "=true") || strings.HasSuffix(arg, "=false") { flag := strings.ToLower(strings.TrimLeft(arg, "-")) flag = strings.TrimSuffix(flag, "=true") diff --git a/resolver.go b/resolver.go index 035e0a4..5952c08 100644 --- a/resolver.go +++ b/resolver.go @@ -137,6 +137,7 @@ func newTransport(server string, transportType transport.Type, tlsConfig *tls.Co UserAgent: opts.HTTPUserAgent, Method: opts.HTTPMethod, Timeout: opts.Timeout, + HTTP2: opts.HTTP2, HTTP3: opts.HTTP3, NoPMTUd: !opts.PMTUD, ReuseConn: opts.ReuseConn, diff --git a/transport/http.go b/transport/http.go index ae1a22a..97d807f 100644 --- a/transport/http.go +++ b/transport/http.go @@ -13,18 +13,19 @@ import ( "github.com/quic-go/quic-go" "github.com/quic-go/quic-go/http3" log "github.com/sirupsen/logrus" + "golang.org/x/net/http2" ) // HTTP makes a DNS query over HTTP(s) type HTTP struct { - Server string - TLSConfig *tls.Config - UserAgent string - Method string - Timeout time.Duration - HTTP3 bool - NoPMTUd bool - ReuseConn bool + Server string + TLSConfig *tls.Config + UserAgent string + Method string + Timeout time.Duration + HTTP2, HTTP3 bool + NoPMTUd bool + ReuseConn bool conn *http.Client } @@ -40,6 +41,13 @@ func (h *HTTP) Exchange(m *dns.Msg) (*dns.Msg, error) { Proxy: http.ProxyFromEnvironment, }, } + if h.HTTP2 { + log.Debug("Using HTTP/2") + h.conn.Transport = &http2.Transport{ + TLSClientConfig: h.TLSConfig, + AllowHTTP: true, + } + } if h.HTTP3 { log.Debug("Using HTTP/3") h.conn.Transport = &http3.RoundTripper{