diff --git a/statsig.go b/statsig.go index d586bb9..6177a8e 100644 --- a/statsig.go +++ b/statsig.go @@ -25,8 +25,9 @@ func Initialize(sdkKey string) { type Options struct { API string `json:"api"` APIOverrides APIOverrides `json:"api_overrides"` - Environment Environment `json:"environment"` - LocalMode bool `json:"localMode"` + Transport http.RoundTripper + Environment Environment `json:"environment"` + LocalMode bool `json:"localMode"` ConfigSyncInterval time.Duration IDListSyncInterval time.Duration LoggingInterval time.Duration diff --git a/transport.go b/transport.go index 25fd48d..b5e8961 100644 --- a/transport.go +++ b/transport.go @@ -62,8 +62,11 @@ func newTransport(secret string, options *Options) *transport { api: api, metadata: getStatsigMetadata(), sdkKey: secret, - client: &http.Client{Timeout: time.Second * 3}, - options: options, + client: &http.Client{ + Timeout: time.Second * 3, + Transport: options.Transport, + }, + options: options, } } diff --git a/transport_test.go b/transport_test.go index 5233ce2..3cf69fe 100644 --- a/transport_test.go +++ b/transport_test.go @@ -4,6 +4,7 @@ import ( "encoding/json" "net/http" "net/http/httptest" + "net/url" "testing" ) @@ -85,3 +86,23 @@ func TestRetries(t *testing.T) { t.Errorf("Expected successful request but got error") } } + +func TestProxy(t *testing.T) { + testServerHit := false + testServer := httptest.NewServer(http.HandlerFunc(func(res http.ResponseWriter, req *http.Request) { + res.WriteHeader(http.StatusOK) + testServerHit = true + })) + defer testServer.Close() + in := Empty{} + var out ServerResponse + url, _ := url.Parse(testServer.URL) + opt := &Options{ + Transport: &http.Transport{Proxy: http.ProxyURL(url)}, + } + n := newTransport("secret-123", opt) + _, _ = n.post("/123", in, &out, RequestOptions{}) + if !testServerHit { + t.Errorf("Expected request to hit proxy server") + } +}