Browse code

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 authored on 2014/01/08 17:14:00
Showing 2 changed files
... ...
@@ -140,6 +140,7 @@ func postAuth(srv *Server, version float64, w http.ResponseWriter, r *http.Reque
140 140
 }
141 141
 
142 142
 func getVersion(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
143
+	w.Header().Set("Content-Type", "application/json")
143 144
 	srv.Eng.ServeHTTP(w, r)
144 145
 	return nil
145 146
 }
... ...
@@ -216,6 +217,7 @@ func getImagesViz(srv *Server, version float64, w http.ResponseWriter, r *http.R
216 216
 }
217 217
 
218 218
 func getInfo(srv *Server, version float64, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
219
+	w.Header().Set("Content-Type", "application/json")
219 220
 	srv.Eng.ServeHTTP(w, r)
220 221
 	return nil
221 222
 }
... ...
@@ -49,6 +49,10 @@ func TestGetVersion(t *testing.T) {
49 49
 	if result := v.Get("Version"); result != expected {
50 50
 		t.Errorf("Expected version %s, %s found", expected, result)
51 51
 	}
52
+	expected = "application/json"
53
+	if result := r.HeaderMap.Get("Content-Type"); result != expected {
54
+		t.Errorf("Expected Content-Type %s, %s found", expected, result)
55
+	}
52 56
 }
53 57
 
54 58
 func TestGetInfo(t *testing.T) {
... ...
@@ -84,6 +88,10 @@ func TestGetInfo(t *testing.T) {
84 84
 	if images := i.GetInt("Images"); images != len(initialImages) {
85 85
 		t.Errorf("Expected images: %d, %d found", len(initialImages), images)
86 86
 	}
87
+	expected := "application/json"
88
+	if result := r.HeaderMap.Get("Content-Type"); result != expected {
89
+		t.Errorf("Expected Content-Type %s, %s found", expected, result)
90
+	}
87 91
 }
88 92
 
89 93
 func TestGetEvents(t *testing.T) {