Skip to content
This repository was archived by the owner on Oct 13, 2023. It is now read-only.

Commit 3da3f6c

Browse files
ndeloofthaJeztah
authored andcommitted
restore support for env variables to configure proxy
regression introduced by b34f34 close #39654 Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com> (cherry picked from commit e25e077a2030aa7c438a993085e6aefcd337ca19) Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Upstream-commit: 2fead2a50fe74ab70b17912d14f67aa65f393470 Component: cli
1 parent c272c32 commit 3da3f6c

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

components/cli/cli/command/cli_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"crypto/x509"
77
"fmt"
88
"io/ioutil"
9+
"net/http"
910
"os"
1011
"runtime"
1112
"testing"
@@ -79,6 +80,24 @@ func TestNewAPIClientFromFlagsWithAPIVersionFromEnv(t *testing.T) {
7980
assert.Check(t, is.Equal(customVersion, apiclient.ClientVersion()))
8081
}
8182

83+
func TestNewAPIClientFromFlagsWithHttpProxyEnv(t *testing.T) {
84+
defer env.Patch(t, "HTTP_PROXY", "http://proxy.acme.com:1234")()
85+
defer env.Patch(t, "DOCKER_HOST", "tcp://docker.acme.com:2376")()
86+
87+
opts := &flags.CommonOptions{}
88+
configFile := &configfile.ConfigFile{}
89+
apiclient, err := NewAPIClientFromFlags(opts, configFile)
90+
assert.NilError(t, err)
91+
transport, ok := apiclient.HTTPClient().Transport.(*http.Transport)
92+
assert.Assert(t, ok)
93+
assert.Assert(t, transport.Proxy != nil)
94+
request, err := http.NewRequest(http.MethodGet, "tcp://docker.acme.com:2376", nil)
95+
assert.NilError(t, err)
96+
url, err := transport.Proxy(request)
97+
assert.NilError(t, err)
98+
assert.Check(t, is.Equal("http://proxy.acme.com:1234", url.String()))
99+
}
100+
82101
type fakeClient struct {
83102
client.Client
84103
pingFunc func() (types.Ping, error)

components/cli/cli/context/docker/load.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,8 @@ func (c *Endpoint) ClientOpts() ([]client.Opt, error) {
104104
return nil, err
105105
}
106106
result = append(result,
107-
client.WithHost(c.Host),
108107
withHTTPClient(tlsConfig),
108+
client.WithHost(c.Host),
109109
)
110110

111111
} else {

0 commit comments

Comments
 (0)