Require URLs for DOH addresses (#684)
* Require URLs for DOH addresses * Move time.Now directly above http.Client.Do in DoH * Remove https scheme check from DOH Although the draft RFC explicitly requires that the scheme be https, this was deemed undesirable, so remove it.
This commit is contained in:
parent
350cd086d1
commit
8ccae88257
17
client.go
17
client.go
|
@ -12,7 +12,6 @@ import (
|
|||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
@ -216,17 +215,7 @@ func (c *Client) exchangeDOH(ctx context.Context, m *Msg, a string) (r *Msg, rtt
|
|||
return nil, 0, err
|
||||
}
|
||||
|
||||
// TODO(tmthrgd): Allow the path to be customised?
|
||||
u := &url.URL{
|
||||
Scheme: "https",
|
||||
Host: a,
|
||||
Path: "/.well-known/dns-query",
|
||||
}
|
||||
if u.Port() == "443" {
|
||||
u.Host = u.Hostname()
|
||||
}
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, u.String(), bytes.NewReader(p))
|
||||
req, err := http.NewRequest(http.MethodPost, a, bytes.NewReader(p))
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
}
|
||||
|
@ -234,8 +223,6 @@ func (c *Client) exchangeDOH(ctx context.Context, m *Msg, a string) (r *Msg, rtt
|
|||
req.Header.Set("Content-Type", dohMimeType)
|
||||
req.Header.Set("Accept", dohMimeType)
|
||||
|
||||
t := time.Now()
|
||||
|
||||
hc := http.DefaultClient
|
||||
if c.HTTPClient != nil {
|
||||
hc = c.HTTPClient
|
||||
|
@ -245,6 +232,8 @@ func (c *Client) exchangeDOH(ctx context.Context, m *Msg, a string) (r *Msg, rtt
|
|||
req = req.WithContext(ctx)
|
||||
}
|
||||
|
||||
t := time.Now()
|
||||
|
||||
resp, err := hc.Do(req)
|
||||
if err != nil {
|
||||
return nil, 0, err
|
||||
|
|
|
@ -590,7 +590,7 @@ func TestConcurrentExchanges(t *testing.T) {
|
|||
}
|
||||
|
||||
func TestDoHExchange(t *testing.T) {
|
||||
const addrstr = "dns.cloudflare.com:443"
|
||||
const addrstr = "https://dns.cloudflare.com/dns-query"
|
||||
|
||||
m := new(Msg)
|
||||
m.SetQuestion("miek.nl.", TypeSOA)
|
||||
|
|
Loading…
Reference in New Issue