Local DoH tweaks

This commit is contained in:
Frank Denis 2019-11-28 23:08:23 +01:00
parent 3e5dbee75a
commit 3ef9ec8732

View file

@ -1,6 +1,7 @@
package main package main
import ( import (
"crypto/tls"
"io/ioutil" "io/ioutil"
"net" "net"
"net/http" "net/http"
@ -40,18 +41,20 @@ func (handler localDoHHandler) ServeHTTP(writer http.ResponseWriter, request *ht
return return
} }
writer.Header().Set("Content-Type", "application/dns-message") writer.Header().Set("Content-Type", "application/dns-message")
writer.Header().Set("Content-Length", string(len(response)))
writer.WriteHeader(200) writer.WriteHeader(200)
writer.Write(response) writer.Write(response)
} }
func (proxy *Proxy) localDoHListener(acceptPc *net.TCPListener) { func (proxy *Proxy) localDoHListener(acceptPc *net.TCPListener) {
defer acceptPc.Close() defer acceptPc.Close()
noh2 := make(map[string]func(*http.Server, *tls.Conn, http.Handler))
httpServer := &http.Server{ httpServer := &http.Server{
ReadTimeout: proxy.timeout, ReadTimeout: proxy.timeout,
WriteTimeout: proxy.timeout, WriteTimeout: proxy.timeout,
TLSNextProto: noh2,
Handler: localDoHHandler{proxy: proxy}, Handler: localDoHHandler{proxy: proxy},
} }
httpServer.SetKeepAlivesEnabled(true)
if err := httpServer.ServeTLS(acceptPc, proxy.localDoHCertFile, proxy.localDoHCertKeyFile); err != nil { if err := httpServer.ServeTLS(acceptPc, proxy.localDoHCertFile, proxy.localDoHCertKeyFile); err != nil {
dlog.Fatal(err) dlog.Fatal(err)
} }