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
This commit is contained in:
Miek Gieben
2017-02-06 19:32:48 +00:00
committed by GitHub
parent 77f957d443
commit 123a76c91e
21 changed files with 466 additions and 827 deletions

View File

@@ -13,7 +13,6 @@ import (
// NewLookup create a new proxy with the hosts in host and a Random policy.
func NewLookup(hosts []string) Proxy {
// TODO(miek): maybe add optional protocol parameter?
p := Proxy{Next: nil}
upstream := &staticUpstream{
@@ -22,7 +21,8 @@ func NewLookup(hosts []string) Proxy {
Policy: &Random{},
Spray: nil,
FailTimeout: 10 * time.Second,
MaxFails: 3,
MaxFails: 3, // TODO(miek): disable error checking for simple lookups?
ex: newDNSEx(),
}
for i, host := range hosts {
@@ -31,7 +31,6 @@ func NewLookup(hosts []string) Proxy {
Conns: 0,
Fails: 0,
FailTimeout: upstream.FailTimeout,
Exchanger: newDNSEx(host),
Unhealthy: false,
CheckDown: func(upstream *staticUpstream) UpstreamHostDownFunc {
@@ -50,7 +49,7 @@ func NewLookup(hosts []string) Proxy {
}
upstream.Hosts[i] = uh
}
p.Upstreams = []Upstream{upstream}
p.Upstreams = &[]Upstream{upstream}
return p
}
@@ -72,7 +71,7 @@ func (p Proxy) Forward(state request.Request) (*dns.Msg, error) {
}
func (p Proxy) lookup(state request.Request) (*dns.Msg, error) {
for _, upstream := range p.Upstreams {
for _, upstream := range *p.Upstreams {
start := time.Now()
// Since Select() should give us "up" hosts, keep retrying
@@ -88,7 +87,7 @@ func (p Proxy) lookup(state request.Request) (*dns.Msg, error) {
atomic.AddInt64(&host.Conns, 1)
reply, backendErr := host.Exchange(state)
reply, backendErr := upstream.Exchanger().Exchange(host.Name, state)
atomic.AddInt64(&host.Conns, -1)