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>
This commit is contained in:
parent
8ecde0f37b
commit
fe2b5f630d
2 changed files with 12 additions and 1 deletions
|
@ -2,6 +2,7 @@ package dnsserver
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net"
|
"net"
|
||||||
|
"net/http"
|
||||||
|
|
||||||
"github.com/coredns/coredns/plugin/pkg/nonwriter"
|
"github.com/coredns/coredns/plugin/pkg/nonwriter"
|
||||||
)
|
)
|
||||||
|
@ -14,6 +15,9 @@ type DoHWriter struct {
|
||||||
raddr net.Addr
|
raddr net.Addr
|
||||||
// laddr is our address. This can be optionally set.
|
// laddr is our address. This can be optionally set.
|
||||||
laddr net.Addr
|
laddr net.Addr
|
||||||
|
|
||||||
|
// request is the HTTP request we're currently handling.
|
||||||
|
request *http.Request
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteAddr returns the remote address.
|
// RemoteAddr returns the remote address.
|
||||||
|
@ -21,3 +25,6 @@ func (d *DoHWriter) RemoteAddr() net.Addr { return d.raddr }
|
||||||
|
|
||||||
// LocalAddr returns the local address.
|
// LocalAddr returns the local address.
|
||||||
func (d *DoHWriter) LocalAddr() net.Addr { return d.laddr }
|
func (d *DoHWriter) LocalAddr() net.Addr { return d.laddr }
|
||||||
|
|
||||||
|
// Request returns the HTTP request
|
||||||
|
func (d *DoHWriter) Request() *http.Request { return d.request }
|
||||||
|
|
|
@ -140,7 +140,11 @@ func (s *ServerHTTPS) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
// Create a DoHWriter with the correct addresses in it.
|
// Create a DoHWriter with the correct addresses in it.
|
||||||
h, p, _ := net.SplitHostPort(r.RemoteAddr)
|
h, p, _ := net.SplitHostPort(r.RemoteAddr)
|
||||||
port, _ := strconv.Atoi(p)
|
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 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.
|
// We should expect a packet to be returned that we can send to the client.
|
||||||
|
|
Loading…
Add table
Reference in a new issue