From 1a73ec8e42310b4c09cc473411b4f67e80b3bd48 Mon Sep 17 00:00:00 2001 From: Lionel Fleury Date: Tue, 5 Nov 2024 16:43:01 +0100 Subject: [PATCH] Fix regression with HTTP Client and Proxy environment variables Fixes #319 --- collector/collector.go | 1 + collector/collector_test.go | 10 ++++++++++ 2 files changed, 11 insertions(+) diff --git a/collector/collector.go b/collector/collector.go index 2e5241d..39ed018 100644 --- a/collector/collector.go +++ b/collector/collector.go @@ -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, diff --git a/collector/collector_test.go b/collector/collector_test.go index e863ec8..93fa624 100644 --- a/collector/collector_test.go +++ b/collector/collector_test.go @@ -5,6 +5,7 @@ import ( "io" "net/http" "net/http/httptest" + "os" "testing" ) @@ -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.") + } +}