Skip to content

Commit

Permalink
doh: set http request in writer (#4445)
Browse files Browse the repository at this point in the history
Makes it possible to read the current http request while serving DNS

Signed-off-by: Johnny Bergström <[email protected]>
  • Loading branch information
balboah authored Feb 17, 2021
1 parent 8ecde0f commit fe2b5f6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
7 changes: 7 additions & 0 deletions core/dnsserver/https.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package dnsserver

import (
"net"
"net/http"

"github.com/coredns/coredns/plugin/pkg/nonwriter"
)
Expand All @@ -14,10 +15,16 @@ 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.
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 }
6 changes: 5 additions & 1 deletion core/dnsserver/server_https.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit fe2b5f6

Please sign in to comment.