Skip to content

Commit

Permalink
Fix regression with HTTP Client and Proxy environment variables
Browse files Browse the repository at this point in the history
  • Loading branch information
lionelfleury committed Nov 5, 2024
1 parent f258a69 commit aa0b7a3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
1 change: 1 addition & 0 deletions collector/collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ func NewHTTPClient(timeout, maxIdleConns int) *http.Client {
return &http.Client{
Timeout: connectionTimeout,
Transport: &http.Transport{
Proxy: http.ProxyFromEnvironment,
MaxIdleConns: maxIdleConns,
IdleConnTimeout: connectionTimeout,
ResponseHeaderTimeout: connectionTimeout,
Expand Down
10 changes: 10 additions & 0 deletions collector/collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io"
"net/http"
"net/http/httptest"
"os"
"testing"
)

Expand Down Expand Up @@ -283,3 +284,12 @@ func TestCollectorWithSomeJobsAndAgentsForAQueue(t *testing.T) {
})
}
}

func TestCollectorWithProxy(t *testing.T) {
os.Setenv("HTTP_PROXY", "http://unit.test")
client := NewHTTPClient(1, 1)
proxyHost := client.Transport.(*http.Transport).Proxy
if proxyHost == nil {
t.Fatalf("Proxy was not picked up from env.")
}
}

0 comments on commit aa0b7a3

Please sign in to comment.