Skip to content

Commit 4c1748a

Browse files
authored
When constructing a client with a proxy, don't override the global http transport (#827)
1 parent 8beb0d5 commit 4c1748a

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

pkg/backplaneapi/clientUtils.go

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,18 +62,22 @@ func (s *DefaultClientUtilsImpl) MakeRawBackplaneAPIClientWithAccessToken(base,
6262
// makeRawBackplaneAPIClientWithAccessTokenCustomProxy creates a BackplaneApi.ClientInterface with a custom proxy url
6363
// proxyURL is optional, the default behavior is no proxy.
6464
func makeRawBackplaneAPIClientWithAccessTokenCustomProxy(server string, accessToken string, proxyURL string) (BackplaneApi.ClientInterface, error) {
65-
co := makeClientOptions(accessToken)
65+
clientOpts := makeClientOptions(accessToken)
6666

6767
if proxyURL != "" {
68-
proxy, err := url.Parse(proxyURL)
68+
httpClient, err := httpDoerWithProxy(proxyURL)
6969
if err != nil {
70-
return nil, err
70+
return nil, fmt.Errorf("failed to create http client: %w", err)
7171
}
72-
http.DefaultTransport = &http.Transport{Proxy: http.ProxyURL(proxy)}
7372
logger.Debugf("Using backplane Proxy URL: %s\n", proxyURL)
73+
74+
return BackplaneApi.NewClient(
75+
server,
76+
clientOpts, BackplaneApi.WithHTTPClient(httpClient),
77+
)
7478
}
7579

76-
return BackplaneApi.NewClient(server, co)
80+
return BackplaneApi.NewClient(server, clientOpts)
7781
}
7882

7983
func (s *DefaultClientUtilsImpl) MakeRawBackplaneAPIClient(base string) (BackplaneApi.ClientInterface, error) {
@@ -136,3 +140,14 @@ func (s *DefaultClientUtilsImpl) SetClientProxyURL(proxyURL string) error {
136140
s.clientProxyURL = proxyURL
137141
return nil
138142
}
143+
144+
func httpDoerWithProxy(proxyURL string) (*http.Client, error) {
145+
proxy, err := url.Parse(proxyURL)
146+
if err != nil {
147+
return nil, err
148+
}
149+
150+
return &http.Client{
151+
Transport: &http.Transport{Proxy: http.ProxyURL(proxy)},
152+
}, nil
153+
}

0 commit comments

Comments
 (0)