Skip to content

Commit 243572e

Browse files
committed
httpdo* with global proxy
1 parent 572df21 commit 243572e

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

modules/http-helper/http_helper.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -262,9 +262,8 @@ func HTTPDoWithOptionsE(
262262
) (int, string, error) {
263263
logger.Default.Logf(t, "Making an HTTP %s call to URL %s", options.Method, options.Url)
264264

265-
tr := &http.Transport{
266-
TLSClientConfig: options.TlsConfig,
267-
}
265+
tr := http.DefaultTransport.(*http.Transport).Clone()
266+
tr.TLSClientConfig = options.TlsConfig
268267

269268
client := http.Client{
270269
// By default, Go does not impose a timeout, so an HTTP connection attempt can hang for a LONG time.

modules/http-helper/http_helper_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"testing"
1212
"time"
1313

14+
"github.com/stretchr/testify/assert"
1415
"github.com/stretchr/testify/require"
1516
)
1617

@@ -204,3 +205,26 @@ func failRetryHandler(w http.ResponseWriter, r *http.Request) {
204205
w.Write(bytes)
205206
}
206207
}
208+
209+
func TestGlobalProxy(t *testing.T) {
210+
proxiedURL := ""
211+
httpProxy := getTestServerForFunction(func(w http.ResponseWriter, r *http.Request) {
212+
proxiedURL = r.RequestURI
213+
bodyCopyHandler(w, r)
214+
})
215+
t.Cleanup(httpProxy.Close)
216+
217+
t.Setenv("HTTP_PROXY", httpProxy.URL)
218+
targetURL := "http://www.notexist.com/"
219+
body := "should be copied"
220+
221+
st, b, err := HTTPDoWithOptionsE(t, HttpDoOptions{
222+
Url: targetURL,
223+
Method: http.MethodPost,
224+
Body: strings.NewReader(body),
225+
})
226+
require.NoError(t, err)
227+
assert.Equal(t, http.StatusOK, st)
228+
assert.Equal(t, targetURL, proxiedURL)
229+
assert.Equal(t, body, b)
230+
}

0 commit comments

Comments
 (0)