Parcourir la source

Fix for #3345: Add Content-Type Header "application/json" to GET /version and /info responses in remote API

Docker-DCO-1.0-Signed-off-by: Manuel Woelker <github@manuel.woelker.org> (github: manuel-woelker)
Manuel Woelker il y a 11 ans
Parent
commit
53a01aebd6
2 fichiers modifiés avec 10 ajouts et 0 suppressions
  1. 2 0
      api.go
  2. 8 0
      integration/api_test.go

+ 2 - 0
api.go

@@ -140,6 +140,7 @@ func postAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Reque
 }
 }
 
 
 func getVersion(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
 func getVersion(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
+	w.Header().Set("Content-Type", "application/json")
 	srv.Eng.ServeHTTP(w, r)
 	srv.Eng.ServeHTTP(w, r)
 	return nil
 	return nil
 }
 }
@@ -216,6 +217,7 @@ func getImagesViz(srv *Server, version float64, w http.ResponseWriter, r *http.R
 }
 }
 
 
 func getInfo(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
 func getInfo(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
+	w.Header().Set("Content-Type", "application/json")
 	srv.Eng.ServeHTTP(w, r)
 	srv.Eng.ServeHTTP(w, r)
 	return nil
 	return nil
 }
 }

+ 8 - 0
integration/api_test.go

@@ -49,6 +49,10 @@ func TestGetVersion(t *testing.T) {
 	if result := v.Get("Version"); result != expected {
 	if result := v.Get("Version"); result != expected {
 		t.Errorf("Expected version %s, %s found", expected, result)
 		t.Errorf("Expected version %s, %s found", expected, result)
 	}
 	}
+	expected = "application/json"
+	if result := r.HeaderMap.Get("Content-Type"); result != expected {
+		t.Errorf("Expected Content-Type %s, %s found", expected, result)
+	}
 }
 }
 
 
 func TestGetInfo(t *testing.T) {
 func TestGetInfo(t *testing.T) {
@@ -84,6 +88,10 @@ func TestGetInfo(t *testing.T) {
 	if images := i.GetInt("Images"); images != len(initialImages) {
 	if images := i.GetInt("Images"); images != len(initialImages) {
 		t.Errorf("Expected images: %d, %d found", len(initialImages), images)
 		t.Errorf("Expected images: %d, %d found", len(initialImages), images)
 	}
 	}
+	expected := "application/json"
+	if result := r.HeaderMap.Get("Content-Type"); result != expected {
+		t.Errorf("Expected Content-Type %s, %s found", expected, result)
+	}
 }
 }
 
 
 func TestGetEvents(t *testing.T) {
 func TestGetEvents(t *testing.T) {