diff options
author | 2017-02-06 19:32:48 +0000 | |
---|---|---|
committer | 2017-02-06 19:32:48 +0000 | |
commit | 123a76c91ead7fb57e801f974a16fc3ab8312c0d (patch) | |
tree | 0b84ec261ad06e8e747c154264fca84043d07aaa /middleware/httpproxy/proxy.go | |
parent | 77f957d443f9c287abc1f315cebc0c725e9e4ba0 (diff) | |
download | coredns-123a76c91ead7fb57e801f974a16fc3ab8312c0d.tar.gz coredns-123a76c91ead7fb57e801f974a16fc3ab8312c0d.tar.zst coredns-123a76c91ead7fb57e801f974a16fc3ab8312c0d.zip |
middleware/proxy: absorb httpproxy (#481)
* middleware/proxy: absorb httpproxy
Move the httproxy into proxy. This adds and Exchanger interface which
is used to exchange the messages with the upstream.
The https_google upstream will re-resolve itself and update the upstream
hosts used every 300s.
* Remove and add TODO
Diffstat (limited to 'middleware/httpproxy/proxy.go')
-rw-r--r-- | middleware/httpproxy/proxy.go | 45 |
1 files changed, 0 insertions, 45 deletions
diff --git a/middleware/httpproxy/proxy.go b/middleware/httpproxy/proxy.go deleted file mode 100644 index 3ef638a8f..000000000 --- a/middleware/httpproxy/proxy.go +++ /dev/null @@ -1,45 +0,0 @@ -// Package httpproxy is middleware that proxies requests to a HTTPs server doing DNS. -package httpproxy - -import ( - "errors" - "time" - - "github.com/miekg/coredns/middleware" - "github.com/miekg/coredns/request" - - "github.com/miekg/dns" - "golang.org/x/net/context" -) - -var errUnreachable = errors.New("unreachable backend") - -// Proxy represents a middleware instance that can proxy requests to HTTPS servers. -type Proxy struct { - from string - e Exchanger - - Next middleware.Handler -} - -// ServeDNS satisfies the middleware.Handler interface. -func (p *Proxy) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) { - start := time.Now() - state := request.Request{W: w, Req: r} - - reply, backendErr := p.e.Exchange(state) - - if backendErr == nil && reply != nil { - state.SizeAndDo(reply) - - w.WriteMsg(reply) - RequestDuration.WithLabelValues(p.from).Observe(float64(time.Since(start) / time.Millisecond)) - return 0, nil - } - RequestDuration.WithLabelValues(p.from).Observe(float64(time.Since(start) / time.Millisecond)) - - return dns.RcodeServerFailure, errUnreachable -} - -// Name implements the Handler interface. -func (p Proxy) Name() string { return "httpproxy" } |