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/upstream.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/upstream.go')
-rw-r--r-- | middleware/httpproxy/upstream.go | 92 |
1 files changed, 0 insertions, 92 deletions
diff --git a/middleware/httpproxy/upstream.go b/middleware/httpproxy/upstream.go deleted file mode 100644 index 3342cce6f..000000000 --- a/middleware/httpproxy/upstream.go +++ /dev/null @@ -1,92 +0,0 @@ -package httpproxy - -import ( - "sync/atomic" - "time" - - "github.com/miekg/coredns/middleware/pkg/dnsutil" - "github.com/miekg/coredns/middleware/proxy" -) - -type simpleUpstream struct { - from string - Hosts proxy.HostPool - Policy proxy.Policy - - FailTimeout time.Duration - MaxFails int32 -} - -// newSimpleUpstream return a new simpleUpstream initialized with the addresses. -func newSimpleUpstream(hosts []string) (*simpleUpstream, error) { - upstream := &simpleUpstream{ - Hosts: nil, - Policy: &proxy.Random{}, - FailTimeout: 3 * time.Second, - MaxFails: 3, - } - - toHosts, err := dnsutil.ParseHostPortOrFile(hosts...) - if err != nil { - return upstream, err - } - - upstream.Hosts = make([]*proxy.UpstreamHost, len(toHosts)) - for i, host := range toHosts { - uh := &proxy.UpstreamHost{ - Name: host, - Conns: 0, - Fails: 0, - FailTimeout: upstream.FailTimeout, - Unhealthy: false, - - CheckDown: func(upstream *simpleUpstream) proxy.UpstreamHostDownFunc { - return func(uh *proxy.UpstreamHost) bool { - if uh.Unhealthy { - return true - } - - fails := atomic.LoadInt32(&uh.Fails) - if fails >= upstream.MaxFails && upstream.MaxFails != 0 { - return true - } - return false - } - }(upstream), - } - upstream.Hosts[i] = uh - } - return upstream, nil -} - -func (u *simpleUpstream) From() string { return u.from } -func (u *simpleUpstream) Options() proxy.Options { return proxy.Options{} } -func (u *simpleUpstream) IsAllowedPath(name string) bool { return true } - -func (u *simpleUpstream) Select() *proxy.UpstreamHost { - pool := u.Hosts - if len(pool) == 1 { - if pool[0].Down() { - return nil - } - return pool[0] - } - allDown := true - for _, host := range pool { - if !host.Down() { - allDown = false - break - } - } - if allDown { - return nil - } - - if u.Policy == nil { - h := (&proxy.Random{}).Select(pool) - return h - } - - h := u.Policy.Select(pool) - return h -} |