Skip to content

Commit

Permalink
feat: add http2 flag (#81)
Browse files Browse the repository at this point in the history
  • Loading branch information
natesales committed Dec 20, 2023
1 parent cc75b6e commit eac353c
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 9 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)"`
Expand Down Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions resolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
24 changes: 16 additions & 8 deletions transport/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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{
Expand Down

0 comments on commit eac353c

Please sign in to comment.