Skip to content

Commit 2a89219

Browse files
committed
add function to read HTTP_PROXY/HTTPS_PROXY/NO_PROXY environment variables
1 parent 66d6897 commit 2a89219

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

internal/api/api.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,23 @@ func buildTransport(opts ClientOpts, flags *Flags) http.RoundTripper {
119119
return transport
120120
}
121121

122+
// envProxyURL resolves the proxy URL
123+
// from standard HTTP_PROXY/HTTPS_PROXY/NO_PROXY
124+
// environment variables for the given endpoint.
125+
// Returns nil if the endpoint is not a valid URL,
126+
// no proxy is configured, or the endpoint is excluded.
127+
func envProxyURL(endpoint string) *url.URL {
128+
u, err := url.Parse(endpoint)
129+
if err != nil || u.Scheme == "" || u.Host == "" {
130+
return nil
131+
}
132+
proxyURL, err := http.ProxyFromEnvironment(&http.Request{URL: u})
133+
if err != nil || proxyURL == nil {
134+
return nil
135+
}
136+
return proxyURL
137+
}
138+
122139
// NewClient creates a new API client.
123140
func NewClient(opts ClientOpts) Client {
124141
if opts.Out == nil {

0 commit comments

Comments
 (0)