middleware/proxy: multiple enhancements (#145)

Add port 53 in the proxy host if not specified.
Check if the host is actually an IP address (v4 or v6)
Remove the http headers and other TODOs
This commit is contained in:
Miek Gieben
2016-04-30 15:54:41 +01:00
parent 14b84ce02b
commit e635b4e773
7 changed files with 86 additions and 62 deletions

View File

@@ -4,7 +4,6 @@ package proxy
// style as the proxy.
import (
"net/http"
"sync/atomic"
"time"
@@ -17,22 +16,20 @@ func New(hosts []string) Proxy {
p := Proxy{Next: nil, Client: Clients()}
upstream := &staticUpstream{
from: "",
proxyHeaders: make(http.Header),
Hosts: make([]*UpstreamHost, len(hosts)),
Policy: &Random{},
FailTimeout: 10 * time.Second,
MaxFails: 1,
from: "",
Hosts: make([]*UpstreamHost, len(hosts)),
Policy: &Random{},
FailTimeout: 10 * time.Second,
MaxFails: 1,
}
for i, host := range hosts {
uh := &UpstreamHost{
Name: host,
Conns: 0,
Fails: 0,
FailTimeout: upstream.FailTimeout,
Unhealthy: false,
ExtraHeaders: upstream.proxyHeaders, // TODO(miek): fixer the fix
Name: host,
Conns: 0,
Fails: 0,
FailTimeout: upstream.FailTimeout,
Unhealthy: false,
CheckDown: func(upstream *staticUpstream) UpstreamHostDownFunc {
return func(uh *UpstreamHost) bool {
if uh.Unhealthy {