From 32c135314dd9573d54f5ec104537f9b51eb772f2 Mon Sep 17 00:00:00 2001 From: Victor Vieux Date: Thu, 15 Jan 2015 00:59:38 +0000 Subject: [PATCH] fix headers Signed-off-by: Victor Vieux --- api/api.go | 8 ++++++++ api/utils.go | 12 ++++++++++++ 2 files changed, 20 insertions(+) diff --git a/api/api.go b/api/api.go index 49c3e75a28..b4c055e177 100644 --- a/api/api.go +++ b/api/api.go @@ -51,6 +51,7 @@ func getInfo(c *context, w http.ResponseWriter, r *http.Request) { c.debug, } + w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(info) } @@ -72,6 +73,7 @@ func getVersion(c *context, w http.ResponseWriter, r *http.Request) { Arch: runtime.GOARCH, } + w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(version) } @@ -112,6 +114,8 @@ func getContainersJSON(c *context, w http.ResponseWriter, r *http.Request) { } sort.Sort(sort.Reverse(ContainerSorter(out))) + + w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(out) } @@ -143,6 +147,8 @@ func getContainerJSON(c *context, w http.ResponseWriter, r *http.Request) { // insert node IP data = bytes.Replace(data, []byte("\"HostIp\":\"0.0.0.0\""), []byte(fmt.Sprintf("\"HostIp\":%q", container.Node.IP)), -1) + + w.Header().Set("Content-Type", "application/json") w.Write(data) } } @@ -170,6 +176,8 @@ func postContainersCreate(c *context, w http.ResponseWriter, r *http.Request) { httpError(w, err.Error(), http.StatusInternalServerError) return } + + w.Header().Set("Content-Type", "application/json") fmt.Fprintf(w, "{%q:%q}", "Id", container.Id) return } diff --git a/api/utils.go b/api/utils.go index 4d17a528a0..98fe751064 100644 --- a/api/utils.go +++ b/api/utils.go @@ -41,6 +41,16 @@ func getContainerFromVars(c *context, vars map[string]string) (*cluster.Containe return nil, errors.New("Not found") } +// from https://github.com/golang/go/blob/master/src/net/http/httputil/reverseproxy.go#L82 +func copyHeader(dst, src http.Header) { + for k, vv := range src { + for _, v := range vv { + fmt.Println(k, v) + dst.Add(k, v) + } + } +} + func proxy(tlsConfig *tls.Config, container *cluster.Container, w http.ResponseWriter, r *http.Request) error { // Use a new client for each request client, scheme := newClientAndScheme(tlsConfig) @@ -56,6 +66,8 @@ func proxy(tlsConfig *tls.Config, container *cluster.Container, w http.ResponseW if err != nil { return err } + + copyHeader(w.Header(), resp.Header) w.WriteHeader(resp.StatusCode) io.Copy(w, resp.Body)