prevent panics when using DoHWriter (#6120)
Signed-off-by: Ondřej Benkovský <ondrej.benkovsky@jamf.com>
This commit is contained in:
parent
d3965b8b60
commit
c74c212bdf
1 changed files with 43 additions and 8 deletions
|
@ -4,13 +4,11 @@ import (
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/coredns/coredns/plugin/pkg/nonwriter"
|
"github.com/miekg/dns"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DoHWriter is a nonwriter.Writer that adds more specific LocalAddr and RemoteAddr methods.
|
// DoHWriter is a dns.ResponseWriter that adds more specific LocalAddr and RemoteAddr methods.
|
||||||
type DoHWriter struct {
|
type DoHWriter struct {
|
||||||
nonwriter.Writer
|
|
||||||
|
|
||||||
// raddr is the remote's address. This can be optionally set.
|
// raddr is the remote's address. This can be optionally set.
|
||||||
raddr net.Addr
|
raddr net.Addr
|
||||||
// laddr is our address. This can be optionally set.
|
// laddr is our address. This can be optionally set.
|
||||||
|
@ -18,13 +16,50 @@ type DoHWriter struct {
|
||||||
|
|
||||||
// request is the HTTP request we're currently handling.
|
// request is the HTTP request we're currently handling.
|
||||||
request *http.Request
|
request *http.Request
|
||||||
|
|
||||||
|
// Msg is a response to be written to the client.
|
||||||
|
Msg *dns.Msg
|
||||||
|
}
|
||||||
|
|
||||||
|
// WriteMsg stores the message to be written to the client.
|
||||||
|
func (d *DoHWriter) WriteMsg(m *dns.Msg) error {
|
||||||
|
d.Msg = m
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Write stores the message to be written to the client.
|
||||||
|
func (d *DoHWriter) Write(b []byte) (int, error) {
|
||||||
|
d.Msg = new(dns.Msg)
|
||||||
|
return len(b), d.Msg.Unpack(b)
|
||||||
}
|
}
|
||||||
|
|
||||||
// RemoteAddr returns the remote address.
|
// RemoteAddr returns the remote address.
|
||||||
func (d *DoHWriter) RemoteAddr() net.Addr { return d.raddr }
|
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
|
// Request returns the HTTP request.
|
||||||
func (d *DoHWriter) Request() *http.Request { return d.request }
|
func (d *DoHWriter) Request() *http.Request {
|
||||||
|
return d.request
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close no-op implementation.
|
||||||
|
func (d *DoHWriter) Close() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// TsigStatus no-op implementation.
|
||||||
|
func (d *DoHWriter) TsigStatus() error {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// TsigTimersOnly no-op implementation.
|
||||||
|
func (d *DoHWriter) TsigTimersOnly(_ bool) {}
|
||||||
|
|
||||||
|
// Hijack no-op implementation.
|
||||||
|
func (d *DoHWriter) Hijack() {}
|
||||||
|
|
Loading…
Add table
Reference in a new issue