fix headers

Signed-off-by: Victor Vieux <vieux@docker.com>
This commit is contained in:
Victor Vieux 2015-01-15 00:59:38 +00:00
parent 9fdb28ebd4
commit 32c135314d
2 changed files with 20 additions and 0 deletions

View File

@ -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
}

View File

@ -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)