99 "net"
1010 "net/http"
1111 "net/url"
12+ "os"
1213 "sync"
1314 "time"
1415)
@@ -20,11 +21,22 @@ var (
2021 desktopProxyTransportInst http.RoundTripper
2122)
2223
23- // ProxyTransport returns an HTTP transport configured to use Docker Desktop's HTTP proxy socket
24- // when Docker Desktop is running. If Docker Desktop is not running, it returns http.DefaultTransport.
24+ // ProxyTransport returns an HTTP transport configured to proxy HTTP requests.
25+ // If HTTP_PROXY/HTTPS_PROXY environment variables are set, they take precedence and
26+ // are respected via http.ProxyFromEnvironment. Otherwise, when Docker Desktop is running,
27+ // traffic is routed through Docker Desktop's HTTP proxy socket. If neither applies,
28+ // http.DefaultTransport is returned.
2529// The transport is initialized once using sync.Once and cached for subsequent calls.
2630func ProxyTransport () http.RoundTripper {
2731 desktopProxyTransportOnce .Do (func () {
32+ // Env proxy vars take precedence over Docker Desktop's proxy socket.
33+ if hasEnvProxyVars () {
34+ desktopProxyTransportInst = & http.Transport {
35+ Proxy : http .ProxyFromEnvironment ,
36+ }
37+ return
38+ }
39+
2840 ctx := context .Background ()
2941 if ! IsRunningInDockerDesktop (ctx ) {
3042 desktopProxyTransportInst = http .DefaultTransport
@@ -44,6 +56,16 @@ func ProxyTransport() http.RoundTripper {
4456 return desktopProxyTransportInst
4557}
4658
59+ // hasEnvProxyVars returns true if any HTTP proxy environment variables are set.
60+ func hasEnvProxyVars () bool {
61+ for _ , name := range []string {"HTTP_PROXY" , "HTTPS_PROXY" , "http_proxy" , "https_proxy" } {
62+ if os .Getenv (name ) != "" {
63+ return true
64+ }
65+ }
66+ return false
67+ }
68+
4769func AvoidResourceSaverMode (ctx context.Context ) {
4870 _ = ClientBackend .Post (ctx , "/idle/make-busy" , nil , nil )
4971}
0 commit comments