http: allow specifying Go DNS resolver on config backends
This commit is contained in:
@@ -23,6 +23,10 @@ type Backend struct {
|
||||
|
||||
// IpHeader HTTP header to set containing the IP header. Set - to forcefully ignore global defaults.
|
||||
IpHeader string `yaml:"ip-header"`
|
||||
|
||||
// GoDNS Resolve URL using the Go DNS server
|
||||
// Only relevant when running with CGO enabled
|
||||
GoDNS bool `yaml:"go-dns"`
|
||||
}
|
||||
|
||||
func (b Backend) Create() (*httputil.ReverseProxy, error) {
|
||||
@@ -30,7 +34,7 @@ func (b Backend) Create() (*httputil.ReverseProxy, error) {
|
||||
b.IpHeader = ""
|
||||
}
|
||||
|
||||
proxy, err := utils.MakeReverseProxy(b.URL)
|
||||
proxy, err := utils.MakeReverseProxy(b.URL, b.GoDNS)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@@ -69,7 +69,7 @@ func EnsureNoOpenRedirect(redirect string) (string, error) {
|
||||
return uri.String(), nil
|
||||
}
|
||||
|
||||
func MakeReverseProxy(target string) (*httputil.ReverseProxy, error) {
|
||||
func MakeReverseProxy(target string, goDns bool) (*httputil.ReverseProxy, error) {
|
||||
u, err := url.Parse(target)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to parse target URL: %w", err)
|
||||
@@ -90,6 +90,13 @@ func MakeReverseProxy(target string) (*httputil.ReverseProxy, error) {
|
||||
}
|
||||
// tell transport how to handle the unix url scheme
|
||||
transport.RegisterProtocol("unix", UnixRoundTripper{Transport: transport})
|
||||
} else if goDns {
|
||||
dialer := &net.Dialer{
|
||||
Resolver: &net.Resolver{
|
||||
PreferGo: true,
|
||||
},
|
||||
}
|
||||
transport.DialContext = dialer.DialContext
|
||||
}
|
||||
|
||||
rp := httputil.NewSingleHostReverseProxy(u)
|
||||
|
Reference in New Issue
Block a user