aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Johnny Bergström <github@joonix.se> 2021-02-17 20:45:04 +0100
committerGravatar GitHub <noreply@github.com> 2021-02-17 20:45:04 +0100
commitfe2b5f630d969bac5eda7b72e28f740e65778469 (patch)
tree7093d32dd4364e5b1e4f2ec2327dbed75a13852f
parent8ecde0f37b80178bb1603581fb0965d1eb490844 (diff)
downloadcoredns-fe2b5f630d969bac5eda7b72e28f740e65778469.tar.gz
coredns-fe2b5f630d969bac5eda7b72e28f740e65778469.tar.zst
coredns-fe2b5f630d969bac5eda7b72e28f740e65778469.zip
doh: set http request in writer (#4445)
Makes it possible to read the current http request while serving DNS Signed-off-by: Johnny Bergström <johnny@klaudify.se>
-rw-r--r--core/dnsserver/https.go7
-rw-r--r--core/dnsserver/server_https.go6
2 files changed, 12 insertions, 1 deletions
diff --git a/core/dnsserver/https.go b/core/dnsserver/https.go
index 532124575..382e06efe 100644
--- a/core/dnsserver/https.go
+++ b/core/dnsserver/https.go
@@ -2,6 +2,7 @@ package dnsserver
import (
"net"
+ "net/http"
"github.com/coredns/coredns/plugin/pkg/nonwriter"
)
@@ -14,6 +15,9 @@ type DoHWriter struct {
raddr net.Addr
// laddr is our address. This can be optionally set.
laddr net.Addr
+
+ // request is the HTTP request we're currently handling.
+ request *http.Request
}
// RemoteAddr returns the remote address.
@@ -21,3 +25,6 @@ func (d *DoHWriter) RemoteAddr() net.Addr { return d.raddr }
// LocalAddr returns the local address.
func (d *DoHWriter) LocalAddr() net.Addr { return d.laddr }
+
+// Request returns the HTTP request
+func (d *DoHWriter) Request() *http.Request { return d.request }
diff --git a/core/dnsserver/server_https.go b/core/dnsserver/server_https.go
index 7292311e8..5962a5f09 100644
--- a/core/dnsserver/server_https.go
+++ b/core/dnsserver/server_https.go
@@ -140,7 +140,11 @@ func (s *ServerHTTPS) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// Create a DoHWriter with the correct addresses in it.
h, p, _ := net.SplitHostPort(r.RemoteAddr)
port, _ := strconv.Atoi(p)
- dw := &DoHWriter{laddr: s.listenAddr, raddr: &net.TCPAddr{IP: net.ParseIP(h), Port: port}}
+ dw := &DoHWriter{
+ laddr: s.listenAddr,
+ raddr: &net.TCPAddr{IP: net.ParseIP(h), Port: port},
+ request: r,
+ }
// We just call the normal chain handler - all error handling is done there.
// We should expect a packet to be returned that we can send to the client.