Do not hardcode http as plugin URL scheme for secure connections.
Signed-off-by: David Calavera <david.calavera@gmail.com>
This commit is contained in:
parent
c8e890aa4b
commit
f624804e8f
2 changed files with 26 additions and 4 deletions
|
@ -40,12 +40,18 @@ func NewClient(addr string, tlsConfig tlsconfig.Options) (*Client, error) {
|
||||||
|
|
||||||
protoAndAddr := strings.Split(addr, "://")
|
protoAndAddr := strings.Split(addr, "://")
|
||||||
sockets.ConfigureTCPTransport(tr, protoAndAddr[0], protoAndAddr[1])
|
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.
|
// Client represents a plugin client.
|
||||||
type Client struct {
|
type Client struct {
|
||||||
http *http.Client // http client to use
|
http *http.Client // http client to use
|
||||||
|
scheme string // scheme protocol of the plugin
|
||||||
addr string // http address of the plugin
|
addr string // http address of the plugin
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -66,7 +72,7 @@ func (c *Client) callWithRetry(serviceMethod string, args interface{}, ret inter
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
req.Header.Add("Accept", versionMimetype)
|
req.Header.Add("Accept", versionMimetype)
|
||||||
req.URL.Scheme = "http"
|
req.URL.Scheme = c.scheme
|
||||||
req.URL.Host = c.addr
|
req.URL.Host = c.addr
|
||||||
|
|
||||||
var retries int
|
var retries int
|
||||||
|
|
|
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue