Skip to content

Commit d9286f3

Browse files
committed
add function to read HTTP_PROXY/HTTPS_PROXY/NO_PROXY environment variables
1 parent ad16cda commit d9286f3

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
@@ -105,6 +105,23 @@ func buildTransport(opts ClientOpts, flags *Flags) *http.Transport {
105105
return transport
106106
}
107107

108+
// envProxyURL resolves the proxy URL
109+
// from standard HTTP_PROXY/HTTPS_PROXY/NO_PROXY
110+
// environment variables for the given endpoint.
111+
// Returns nil if the endpoint is not a valid URL,
112+
// no proxy is configured, or the endpoint is excluded.
113+
func envProxyURL(endpoint string) *url.URL {
114+
u, err := url.Parse(endpoint)
115+
if err != nil || u.Scheme == "" || u.Host == "" {
116+
return nil
117+
}
118+
proxyURL, err := http.ProxyFromEnvironment(&http.Request{URL: u})
119+
if err != nil || proxyURL == nil {
120+
return nil
121+
}
122+
return proxyURL
123+
}
124+
108125
// NewClient creates a new API client.
109126
func NewClient(opts ClientOpts) Client {
110127
if opts.Out == nil {

0 commit comments

Comments
 (0)