From d18a8d0b75f9c9b691216d6281c7dcb1ebc69654 Mon Sep 17 00:00:00 2001 From: Frank Fischer Date: Thu, 13 Jul 2017 15:35:06 +0200 Subject: [PATCH] Fall back on environment http proxies If no explicit proxy url is defined, try to use the proxies (HTTP_PROXY, HTTPS_PROXY, NO_PROXY) defined in the process' environment --- config/http_config.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/config/http_config.go b/config/http_config.go index ff5837fa5..5ff566810 100644 --- a/config/http_config.go +++ b/config/http_config.go @@ -121,9 +121,16 @@ func NewHTTPClientFromConfig(cfg *HTTPClientConfig) (*http.Client, error) { return nil, err } + var proxyFunc func(*http.Request) (*url.URL, error) + if cfg.ProxyURL.URL != nil { + proxyFunc = http.ProxyURL(cfg.ProxyURL.URL) + } else { + proxyFunc = http.ProxyFromEnvironment + } + // It's the caller's job to handle timeouts var rt http.RoundTripper = &http.Transport{ - Proxy: http.ProxyURL(cfg.ProxyURL.URL), + Proxy: proxyFunc, DisableKeepAlives: true, TLSClientConfig: tlsConfig, }