diff --git a/modules/http-helper/http_helper.go b/modules/http-helper/http_helper.go index ff31e7c3e..bc56fae18 100644 --- a/modules/http-helper/http_helper.go +++ b/modules/http-helper/http_helper.go @@ -262,9 +262,8 @@ func HTTPDoWithOptionsE( ) (int, string, error) { logger.Default.Logf(t, "Making an HTTP %s call to URL %s", options.Method, options.Url) - tr := &http.Transport{ - TLSClientConfig: options.TlsConfig, - } + tr := http.DefaultTransport.(*http.Transport).Clone() + tr.TLSClientConfig = options.TlsConfig client := http.Client{ // By default, Go does not impose a timeout, so an HTTP connection attempt can hang for a LONG time. diff --git a/modules/http-helper/http_helper_test.go b/modules/http-helper/http_helper_test.go index 5dfc5af04..7805682a2 100644 --- a/modules/http-helper/http_helper_test.go +++ b/modules/http-helper/http_helper_test.go @@ -11,6 +11,7 @@ import ( "testing" "time" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -204,3 +205,26 @@ func failRetryHandler(w http.ResponseWriter, r *http.Request) { w.Write(bytes) } } + +func TestGlobalProxy(t *testing.T) { + proxiedURL := "" + httpProxy := getTestServerForFunction(func(w http.ResponseWriter, r *http.Request) { + proxiedURL = r.RequestURI + bodyCopyHandler(w, r) + }) + t.Cleanup(httpProxy.Close) + + t.Setenv("HTTP_PROXY", httpProxy.URL) + targetURL := "http://www.notexist.com/" + body := "should be copied" + + st, b, err := HTTPDoWithOptionsE(t, HttpDoOptions{ + Url: targetURL, + Method: http.MethodPost, + Body: strings.NewReader(body), + }) + require.NoError(t, err) + assert.Equal(t, http.StatusOK, st) + assert.Equal(t, targetURL, proxiedURL) + assert.Equal(t, body, b) +}