This question has been asked before but that answer applies to python applications. I'd like to know how to fix the issue for go applications.
I've deployed a web service on Google App Engine which is consumed by mobile clients. Using the function below, I send the response either as XML or JSON (as requested by the client)
func (api *API) Respond(w http.ResponseWriter, r *http.Request, body interface{}, status int) {
var contentType string
var content []byte
var err error
if r.Header.Get("Accept") == "application/xml" {
contentType = "application/xml; charset=UTF-8"
content, err = xml.Marshal(body)
} else {
contentType = "application/json; charset=UTF-8"
content, err = json.MarshalIndent(body, "", " ")
}
if err != nil {
panic(err)
}
w.WriteHeader(status)
w.Header().Set("Content-Type", contentType)
w.Write(content)
}
In either case, however, the client device receives a Content-Type of text/html. How can I fix this? Here's the app.yam file for my application:
application: wks-api
version: 3
runtime: go
api_version: go1
handlers:
- url: /.*
script: api