aboutsummaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/dns/dns.go4
-rw-r--r--lib/dns/server.go32
2 files changed, 12 insertions, 24 deletions
diff --git a/lib/dns/dns.go b/lib/dns/dns.go
index 8e13200d..d6563adc 100644
--- a/lib/dns/dns.go
+++ b/lib/dns/dns.go
@@ -46,10 +46,6 @@ const (
rdataIPv6Size = 16
// sectionHeaderSize define the size of section header in DNS message.
sectionHeaderSize = 12
-
- dohHeaderKeyAccept = "accept"
- dohHeaderKeyContentType = "content-type"
- dohHeaderValDNSMessage = "application/dns-message"
)
// List of error messages.
diff --git a/lib/dns/server.go b/lib/dns/server.go
index 075eecb9..32fd8241 100644
--- a/lib/dns/server.go
+++ b/lib/dns/server.go
@@ -15,7 +15,6 @@ import (
"log"
"net"
"net/http"
- "strings"
"sync"
"time"
)
@@ -246,18 +245,20 @@ func (srv *Server) serveDoH() {
var (
logp = `serveDoH`
addr = srv.opts.getHTTPAddress().String()
-
- err error
)
+ var mux = http.NewServeMux()
+
+ mux.Handle(`/dns-query`, srv)
+
srv.doh = &http.Server{
Addr: addr,
IdleTimeout: srv.opts.HTTPIdleTimeout,
ReadHeaderTimeout: 5 * time.Second,
+ Handler: mux,
}
- http.Handle("/dns-query", srv)
-
+ var err error
if srv.tlsConfig != nil && !srv.opts.DoHBehindProxy {
log.Printf(`%s: listening at %s`, logp, addr)
srv.doh.TLSConfig = srv.tlsConfig
@@ -399,26 +400,17 @@ func (srv *Server) serveUDP() {
}
}
+// ServeHTTP the main handle for DNS-over-HTTPS.
func (srv *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
- var (
- hdr = w.Header()
-
- hdrAcceptValue string
- )
-
- hdr.Set(dohHeaderKeyContentType, dohHeaderValDNSMessage)
-
- hdrAcceptValue = r.Header.Get(dohHeaderKeyAccept)
- if len(hdrAcceptValue) == 0 {
+ const acceptDNSMessage = `application/dns-message`
+ var hdrAcceptValue = r.Header.Get(`Accept`)
+ if hdrAcceptValue != acceptDNSMessage {
w.WriteHeader(http.StatusUnsupportedMediaType)
return
}
- hdrAcceptValue = strings.ToLower(hdrAcceptValue)
- if hdrAcceptValue != dohHeaderValDNSMessage {
- w.WriteHeader(http.StatusUnsupportedMediaType)
- return
- }
+ var hdr = w.Header()
+ hdr.Set(`Content-Type`, acceptDNSMessage)
if r.Method == http.MethodGet {
srv.handleDoHGet(w, r)