coredns/middleware/proxy/reverseproxy.go
Miek Gieben f907311cdf Use context.Context
Rename the old Context to State and use context.Context in the
middleware for intra-middleware communication and more.
2016-03-19 07:32:50 +00:00

36 lines
695 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 {
// TODO(miek): use extra to EDNS0.
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
}