summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Calavera <david.calavera@gmail.com>2015-09-22 15:54:29 -0400
committerDavid Calavera <david.calavera@gmail.com>2015-09-22 15:54:29 -0400
commitdc1761329768d337d7930059b334d45d016ebfd2 (patch)
tree7bfb014e378505e727bd70acd206de583e5addaa
parent04d76d898addae4451db28999a230a0399f08b30 (diff)
downloaddocker-dc1761329768d337d7930059b334d45d016ebfd2.tar.gz
Do not hardcode http as plugin URL scheme for secure connections.
Signed-off-by: David Calavera <david.calavera@gmail.com>
-rw-r--r--pkg/plugins/client.go14
-rw-r--r--pkg/plugins/client_test.go16
2 files changed, 26 insertions, 4 deletions
diff --git a/pkg/plugins/client.go b/pkg/plugins/client.go
index 973858c903..54c386e480 100644
--- a/pkg/plugins/client.go
+++ b/pkg/plugins/client.go
@@ -40,13 +40,19 @@ func NewClient(addr string, tlsConfig tlsconfig.Options) (*Client, error) {
protoAndAddr := strings.Split(addr, "://")
sockets.ConfigureTCPTransport(tr, protoAndAddr[0], protoAndAddr[1])
- return &Client{&http.Client{Transport: tr}, protoAndAddr[1]}, nil
+
+ scheme := protoAndAddr[0]
+ if scheme != "https" {
+ scheme = "http"
+ }
+ return &Client{&http.Client{Transport: tr}, scheme, protoAndAddr[1]}, nil
}
// Client represents a plugin client.
type Client struct {
- http *http.Client // http client to use
- addr string // http address of the plugin
+ http *http.Client // http client to use
+ scheme string // scheme protocol of the plugin
+ addr string // http address of the plugin
}
// Call calls the specified method with the specified arguments for the plugin.
@@ -66,7 +72,7 @@ func (c *Client) callWithRetry(serviceMethod string, args interface{}, ret inter
return err
}
req.Header.Add("Accept", versionMimetype)
- req.URL.Scheme = "http"
+ req.URL.Scheme = c.scheme
req.URL.Host = c.addr
var retries int
diff --git a/pkg/plugins/client_test.go b/pkg/plugins/client_test.go
index 6a2c96f713..60f1263faa 100644
--- a/pkg/plugins/client_test.go
+++ b/pkg/plugins/client_test.go
@@ -105,3 +105,19 @@ func TestAbortRetry(t *testing.T) {
}
}
}
+
+func TestClientScheme(t *testing.T) {
+ cases := map[string]string{
+ "tcp://127.0.0.1:8080": "http",
+ "unix:///usr/local/plugins/foo": "http",
+ "http://127.0.0.1:8080": "http",
+ "https://127.0.0.1:8080": "https",
+ }
+
+ for addr, scheme := range cases {
+ c, _ := NewClient(addr, tlsconfig.Options{InsecureSkipVerify: true})
+ if c.scheme != scheme {
+ t.Fatalf("URL scheme mismatch, expected %s, got %s", scheme, c.scheme)
+ }
+ }
+}