Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

httpdo* with global proxy #1481

Merged
merged 2 commits into from
Dec 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions modules/http-helper/http_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 24 additions & 0 deletions modules/http-helper/http_helper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"testing"
"time"

"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)

Expand Down Expand Up @@ -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)
}