From a0f3f3440bc7265878583826f7fd7943914ef9b5 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Wed, 14 Jan 2015 22:33:24 +0000 Subject: [PATCH] fix inspect Signed-off-by: Victor Vieux --- api/api.go | 4 +++- api/utils.go | 21 ++++++++++----------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/api/api.go b/api/api.go index 8aecd14350..49c3e75a28 100644 --- a/api/api.go +++ b/api/api.go @@ -119,7 +119,9 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) { func getContainerJSON(c *context, w http.ResponseWriter, r *http.Request) { container := c.cluster.Container(mux.Vars(r)["name"]) if container != nil { - resp, err := http.Get(container.Node.Addr + "/containers/" + container.Id + "/json") + client, scheme := newClientAndScheme(c.tlsConfig) + + resp, err := client.Get(scheme + "://" + container.Node.Addr + "/containers/" + container.Id + "/json") if err != nil { httpError(w, err.Error(), http.StatusInternalServerError) return diff --git a/api/utils.go b/api/utils.go index 88f5f79102..4d17a528a0 100644 --- a/api/utils.go +++ b/api/utils.go @@ -13,6 +13,13 @@ import ( "github.com/docker/swarm/cluster" ) +func newClientAndScheme(tlsConfig *tls.Config) (*http.Client, string) { + if tlsConfig != nil { + return &http.Client{Transport: &http.Transport{TLSClientConfig: tlsConfig}}, "https" + } + return &http.Client{}, "http" +} + func getContainerFromVars(c *context, vars map[string]string) (*cluster.Container, error) { if name, ok := vars["name"]; ok { if container := c.cluster.Container(name); container != nil { @@ -36,20 +43,12 @@ func getContainerFromVars(c *context, vars map[string]string) (*cluster.Containe func proxy(tlsConfig *tls.Config, container *cluster.Container, w http.ResponseWriter, r *http.Request) error { // Use a new client for each request - client := &http.Client{ - Transport: &http.Transport{ - TLSClientConfig: tlsConfig, - }, - } - + client, scheme := newClientAndScheme(tlsConfig) // RequestURI may not be sent to client r.RequestURI = "" - if tlsConfig != nil { - r.URL.Scheme = "https" - } else { - r.URL.Scheme = "http" - } + r.URL.Scheme = scheme + r.URL.Host = container.Node.Addr log.Debugf("[PROXY] --> %s %s", r.Method, r.URL)