Skip to content

Commit

Permalink
Merge pull request #865 from robstrong/hotfix/contentType
Browse files Browse the repository at this point in the history
fix(peer_server) set content type to application/json in admin
  • Loading branch information
yichengq committed Jun 23, 2014
2 parents 3efb4d8 + 494d2c6 commit 5524131
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
4 changes: 4 additions & 0 deletions server/peer_server_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ func (ps *PeerServer) RemoveHttpHandler(w http.ResponseWriter, req *http.Request

// Returns a JSON-encoded cluster configuration.
func (ps *PeerServer) getClusterConfigHttpHandler(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(ps.ClusterConfig())
}

Expand Down Expand Up @@ -217,6 +218,7 @@ func (ps *PeerServer) setClusterConfigHttpHandler(w http.ResponseWriter, req *ht
log.Debugf("[recv] Update Cluster Config Request")
ps.server.Dispatch(c, w, req)

w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(ps.ClusterConfig())
}

Expand All @@ -230,13 +232,15 @@ func (ps *PeerServer) getMachinesHttpHandler(w http.ResponseWriter, req *http.Re
}
}

w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(&machines)
}

// Retrieve single peer or standby.
func (ps *PeerServer) getMachineHttpHandler(w http.ResponseWriter, req *http.Request) {
vars := mux.Vars(req)
m := ps.getMachineMessage(vars["name"], ps.raftServer.Leader())
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(m)
}

Expand Down
4 changes: 4 additions & 0 deletions tests/functional/cluster_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestClusterConfigSet(t *testing.T) {
resp, _ = tests.Get("http://localhost:7002/v2/admin/config")
body := tests.ReadBodyJSON(resp)
assert.Equal(t, resp.StatusCode, 200)
assert.Equal(t, resp.Header.Get("Content-Type"), "application/json")
assert.Equal(t, body["activeSize"], 3)
assert.Equal(t, body["removeDelay"], 60)
}
Expand All @@ -44,6 +45,7 @@ func TestClusterConfigReload(t *testing.T) {
resp, _ = tests.Get("http://localhost:7002/v2/admin/config")
body := tests.ReadBodyJSON(resp)
assert.Equal(t, resp.StatusCode, 200)
assert.Equal(t, resp.Header.Get("Content-Type"), "application/json")
assert.Equal(t, body["activeSize"], 3)
assert.Equal(t, body["removeDelay"], 60)

Expand All @@ -59,6 +61,7 @@ func TestClusterConfigReload(t *testing.T) {
resp, _ = tests.Get("http://localhost:7002/v2/admin/config")
body = tests.ReadBodyJSON(resp)
assert.Equal(t, resp.StatusCode, 200)
assert.Equal(t, resp.Header.Get("Content-Type"), "application/json")
assert.Equal(t, body["activeSize"], 3)
assert.Equal(t, body["removeDelay"], 60)
}
Expand All @@ -76,6 +79,7 @@ func TestGetMachines(t *testing.T) {
t.FailNow()
}
assert.Equal(t, resp.StatusCode, 200)
assert.Equal(t, resp.Header.Get("Content-Type"), "application/json")
machines := make([]map[string]interface{}, 0)
b := tests.ReadBody(resp)
json.Unmarshal(b, &machines)
Expand Down

0 comments on commit 5524131

Please sign in to comment.