coredns/middleware/proxy/reverseproxy.go
Yong Tang b9cf32f7a9 Golint middleware/proxy (#290)
While looking into the proxy middleware it appears that there are
several golint messages:
```
ubuntu@ubuntu:~/coredns$ golint middleware/proxy/
middleware/proxy/lookup.go:66:1: exported method Proxy.Forward should have comment or be unexported
middleware/proxy/proxy.go:24:6: exported type Client should have comment or be unexported
middleware/proxy/proxy.go:107:1: exported function Clients should have comment or be unexported
middleware/proxy/reverseproxy.go:10:6: exported type ReverseProxy should have comment or be unexported
middleware/proxy/reverseproxy.go:16:1: exported method ReverseProxy.ServeDNS should have comment or be unexported
middleware/proxy/upstream.go:42:6: exported type Options should have comment or be unexported
```

This fix addressed the above golint messages.

Signed-off-by: Yong Tang <yong.tang.github@outlook.com>
2016-09-23 23:00:50 +01:00

44 lines
856 B
Go

// Package proxy is middleware that proxies requests.
package proxy
import (
"github.com/miekg/coredns/request"
"github.com/miekg/dns"
)
// ReverseProxy is a basic reverse proxy
type ReverseProxy struct {
Host string
Client Client
Options Options
}
// ServeDNS implements the middleware.Handler interface.
func (p ReverseProxy) ServeDNS(w dns.ResponseWriter, r *dns.Msg, extra []dns.RR) error {
var (
reply *dns.Msg
err error
)
switch {
case request.Proto(w) == "tcp": // TODO(miek): keep this in request
reply, _, err = p.Client.TCP.Exchange(r, p.Host)
default:
reply, _, err = p.Client.UDP.Exchange(r, p.Host)
}
if reply != nil && reply.Truncated {
// Suppress proxy error for truncated responses
err = nil
}
if err != nil {
return err
}
reply.Compress = true
reply.Id = r.Id
w.WriteMsg(reply)
return nil
}