Browse code

Fix requests for docker host ending with slash

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>

Tonis Tiigi authored on 2017/08/12 02:47:02
Showing 2 changed files
... ...
@@ -51,6 +51,7 @@ import (
51 51
 	"net/http"
52 52
 	"net/url"
53 53
 	"os"
54
+	"path"
54 55
 	"path/filepath"
55 56
 	"strings"
56 57
 
... ...
@@ -219,9 +220,9 @@ func (cli *Client) getAPIPath(p string, query url.Values) string {
219 219
 	var apiPath string
220 220
 	if cli.version != "" {
221 221
 		v := strings.TrimPrefix(cli.version, "v")
222
-		apiPath = cli.basePath + "/v" + v + p
222
+		apiPath = path.Join(cli.basePath, "/v"+v+p)
223 223
 	} else {
224
-		apiPath = cli.basePath + p
224
+		apiPath = path.Join(cli.basePath, p)
225 225
 	}
226 226
 
227 227
 	u := &url.URL{
... ...
@@ -1,6 +1,8 @@
1 1
 package client
2 2
 
3 3
 import (
4
+	"path"
5
+
4 6
 	"github.com/docker/docker/api/types"
5 7
 	"golang.org/x/net/context"
6 8
 )
... ...
@@ -8,7 +10,7 @@ import (
8 8
 // Ping pings the server and returns the value of the "Docker-Experimental", "OS-Type" & "API-Version" headers
9 9
 func (cli *Client) Ping(ctx context.Context) (types.Ping, error) {
10 10
 	var ping types.Ping
11
-	req, err := cli.buildRequest("GET", cli.basePath+"/_ping", nil, nil)
11
+	req, err := cli.buildRequest("GET", path.Join(cli.basePath, "/_ping"), nil, nil)
12 12
 	if err != nil {
13 13
 		return ping, err
14 14
 	}