Browse Source

etcdhttp: add Content-Type: application/json header to version handler

Xiang Li 10 years ago
parent
commit
1226838381
2 changed files with 4 additions and 0 deletions
  1. 1 0
      etcdserver/etcdhttp/client.go
  2. 3 0
      etcdserver/etcdhttp/client_test.go

+ 1 - 0
etcdserver/etcdhttp/client.go

@@ -381,6 +381,7 @@ func serveVersion(w http.ResponseWriter, r *http.Request, clusterV string) {
 		Cluster: clusterV,
 		Cluster: clusterV,
 	}
 	}
 
 
+	w.Header().Set("Content-Type", "application/json")
 	b, err := json.Marshal(&vs)
 	b, err := json.Marshal(&vs)
 	if err != nil {
 	if err != nil {
 		plog.Panicf("cannot marshal versions to json (%v)", err)
 		plog.Panicf("cannot marshal versions to json (%v)", err)

+ 3 - 0
etcdserver/etcdhttp/client_test.go

@@ -1341,6 +1341,9 @@ func TestServeVersion(t *testing.T) {
 	if g := rw.Body.String(); g != string(w) {
 	if g := rw.Body.String(); g != string(w) {
 		t.Fatalf("body = %q, want %q", g, string(w))
 		t.Fatalf("body = %q, want %q", g, string(w))
 	}
 	}
+	if ct := rw.HeaderMap.Get("Content-Type"); ct != "application/json" {
+		t.Errorf("contet-type header = %s, want %s", ct, "application/json")
+	}
 }
 }
 
 
 func TestServeVersionFails(t *testing.T) {
 func TestServeVersionFails(t *testing.T) {