Skip to content

Commit 0e1df50

Browse files
committed
add function to read HTTP_PROXY/HTTPS_PROXY/NO_PROXY environment variables
1 parent 2475734 commit 0e1df50

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

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

0 commit comments

Comments
 (0)