coredns/middleware/proxy/reverseproxy.go
Miek Gieben 16e50ec5f8 Add state.SizeAndDo()
This methods returns an OPT record which can be used to create a new
message with the same bufsize and Do bit as the original one.
2016-03-25 17:23:06 +00:00

35 lines
659 B
Go

// Package proxy is middleware that proxies requests.
package proxy
import (
"github.com/miekg/coredns/middleware"
"github.com/miekg/dns"
)
type ReverseProxy struct {
Host string
Client Client
}
func (p ReverseProxy) ServeDNS(w dns.ResponseWriter, r *dns.Msg, extra []dns.RR) error {
var (
reply *dns.Msg
err error
)
state := middleware.State{W: w, Req: r}
// tls+tcp ?
if state.Proto() == "tcp" {
reply, err = middleware.Exchange(p.Client.TCP, r, p.Host)
} else {
reply, err = middleware.Exchange(p.Client.UDP, r, p.Host)
}
if err != nil {
return err
}
reply.Compress = true
reply.Id = r.Id
w.WriteMsg(reply)
return nil
}