Set correct Content-Type in the http response (#147)

When the request is handled successfully, json data is returned, this
patch changes the response Content-Type header from text/plain to
application/json

Fixes: #144
This commit is contained in:
Lingxian Kong
2017-03-21 13:51:54 -07:00
committed by Soam Vasani
parent a390c1baa8
commit a3f8016442
2 changed files with 25 additions and 0 deletions
+2
View File
@@ -47,6 +47,7 @@ func MakeAPI(rs *ResourceStore) *API {
}
func (api *API) respondWithSuccess(w http.ResponseWriter, resp []byte) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
_, err := w.Write(resp)
if err != nil {
// this will probably fail too, but try anyway
@@ -62,6 +63,7 @@ func (api *API) respondWithError(w http.ResponseWriter, err error) {
}
func (api *API) HomeHandler(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json; charset=utf-8")
fmt.Fprintf(w, "{\"message\": \"Fission API\", \"version\": \"0.1.0\"}\n")
}