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

Commit 8493931

Browse files
authored
Merge pull request #2061 from thaJeztah/19.03_backport_issue39654
[19.03 backport] restore support for env variables to configure proxy Upstream-commit: c8e9c04d199cd2547977647c1496fab59fa2324e Component: cli
2 parents c272c32 + 3da3f6c commit 8493931

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)