Skip to content

Commit

Permalink
fix: snapshot reporting use HTTP_PROXY and HTTPS_PROXY env vars (#1954)
Browse files Browse the repository at this point in the history
Fix snapshot reporting to use HTTP_PROXY and HTTPS_PROXY env vars
  • Loading branch information
shazlehu authored Nov 19, 2024
1 parent 8895796 commit 1829e93
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
20 changes: 19 additions & 1 deletion internal/report/agent_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ package report

import (
"crypto/tls"
"net"
"net/http"
"time"
)

var _ Client = (*AgentClient)(nil)
Expand All @@ -31,12 +33,28 @@ type AgentClient struct {

// NewAgentClient creates a new AgentClient
func NewAgentClient(agentID string, secretKey *string, tlsConfig *tls.Config) *AgentClient {

// Values are copied from http.DefaultTransport. We don't use a copy of http.DefaultTransport with
// our own values because the http.DefaultTransport struct has private mutexes that we can't copy.
// http.DefaultClient is equivalent to &http.Client{}

dialer := &net.Dialer{
Timeout: 30 * time.Second,
KeepAlive: 30 * time.Second,
}
return &AgentClient{
agentID: agentID,
secretKey: secretKey,
client: &http.Client{
Transport: &http.Transport{
TLSClientConfig: tlsConfig,
Proxy: http.ProxyFromEnvironment,
DialContext: dialer.DialContext,
ForceAttemptHTTP2: true,
MaxIdleConns: 100,
IdleConnTimeout: 90 * time.Second,
TLSHandshakeTimeout: 10 * time.Second,
ExpectContinueTimeout: 1 * time.Second,
TLSClientConfig: tlsConfig,
},
},
}
Expand Down
3 changes: 3 additions & 0 deletions internal/report/agent_client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ func TestNewAgentClient(t *testing.T) {
require.NotNil(t, client.client)
}

// TestAgentClientDo tests the AgentClient Do method
// Note: this unit test can't test the proxy settings since the test server has a loopback address
// (127.*.*.* or localhost) and the proxy settings are ignored for these addresses.
func TestAgentClientDo(t *testing.T) {
secretKey := "secret_key"
testCases := []struct {
Expand Down

0 comments on commit 1829e93

Please sign in to comment.