Преглед на файлове

fix https

Docker-DCO-1.1-Signed-off-by: Victor Vieux <vieux@docker.com> (github: vieux)
Victor Vieux преди 11 години
родител
ревизия
45be6f6dff
променени са 3 файла, в които са добавени 17 реда и са изтрити 6 реда
  1. 7 0
      api/client/cli.go
  2. 5 3
      api/client/utils.go
  3. 5 3
      integration/https_test.go

+ 7 - 0
api/client/cli.go

@@ -65,8 +65,13 @@ func NewDockerCli(in io.ReadCloser, out, err io.Writer, proto, addr string, tlsC
 	var (
 		isTerminal = false
 		terminalFd uintptr
+		scheme     = "http"
 	)
 
+	if tlsConfig != nil {
+		scheme = "https"
+	}
+
 	if in != nil {
 		if file, ok := in.(*os.File); ok {
 			terminalFd = file.Fd()
@@ -86,6 +91,7 @@ func NewDockerCli(in io.ReadCloser, out, err io.Writer, proto, addr string, tlsC
 		isTerminal: isTerminal,
 		terminalFd: terminalFd,
 		tlsConfig:  tlsConfig,
+		scheme:     scheme,
 	}
 }
 
@@ -99,4 +105,5 @@ type DockerCli struct {
 	isTerminal bool
 	terminalFd uintptr
 	tlsConfig  *tls.Config
+	scheme     string
 }

+ 5 - 3
api/client/utils.go

@@ -57,7 +57,7 @@ func (cli *DockerCli) call(method, path string, data interface{}, passAuthInfo b
 		}
 	}
 
-	req, err := http.NewRequest(method, fmt.Sprintf("http://v%s%s", api.APIVERSION, path), params)
+	req, err := http.NewRequest(method, fmt.Sprintf("/v%s%s", api.APIVERSION, path), params)
 	if err != nil {
 		return nil, -1, err
 	}
@@ -82,7 +82,8 @@ func (cli *DockerCli) call(method, path string, data interface{}, passAuthInfo b
 		}
 	}
 	req.Header.Set("User-Agent", "Docker-Client/"+dockerversion.VERSION)
-	req.Host = cli.addr
+	req.URL.Host = cli.addr
+	req.URL.Scheme = cli.scheme
 	if data != nil {
 		req.Header.Set("Content-Type", "application/json")
 	} else if method == "POST" {
@@ -123,7 +124,8 @@ func (cli *DockerCli) streamHelper(method, path string, setRawTerminal bool, in
 		return err
 	}
 	req.Header.Set("User-Agent", "Docker-Client/"+dockerversion.VERSION)
-	req.Host = cli.addr
+	req.URL.Host = cli.addr
+	req.URL.Scheme = cli.scheme
 	if method == "POST" {
 		req.Header.Set("Content-Type", "plain/text")
 	}

+ 5 - 3
integration/https_test.go

@@ -3,10 +3,12 @@ package docker
 import (
 	"crypto/tls"
 	"crypto/x509"
-	"github.com/dotcloud/docker/api/client"
 	"io/ioutil"
+	"strings"
 	"testing"
 	"time"
+
+	"github.com/dotcloud/docker/api/client"
 )
 
 const (
@@ -56,7 +58,7 @@ func TestHttpsInfoRogueCert(t *testing.T) {
 		if err == nil {
 			t.Fatal("Expected error but got nil")
 		}
-		if err.Error() != errBadCertificate {
+		if !strings.Contains(err.Error(), errBadCertificate) {
 			t.Fatalf("Expected error: %s, got instead: %s", errBadCertificate, err)
 		}
 	})
@@ -74,7 +76,7 @@ func TestHttpsInfoRogueServerCert(t *testing.T) {
 			t.Fatal("Expected error but got nil")
 		}
 
-		if err.Error() != errCaUnknown {
+		if !strings.Contains(err.Error(), errCaUnknown) {
 			t.Fatalf("Expected error: %s, got instead: %s", errBadCertificate, err)
 		}