commands/http: Explicitly define the MIME types for each encoding

This commit is contained in:
Matt Bell 2014-10-28 19:31:23 -07:00 committed by Juan Batiz-Benet
parent b54801cc10
commit 714e13b63a

View File

@ -15,6 +15,12 @@ type Handler struct {
var ErrNotFound = errors.New("404 page not found")
var mimeTypes = map[string]string{
cmds.JSON: "application/json",
cmds.XML: "application/xml",
cmds.Text: "text/plain",
}
func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
req, err := Parse(r)
if err != nil {
@ -36,9 +42,9 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
// TODO: set based on actual Content-Type of file
w.Header().Set("Content-Type", "application/octet-stream")
} else {
// TODO: get proper MIME type for encoding from multicodec lib
enc, _ := req.Option(cmds.EncShort)
w.Header().Set("Content-Type", "application/"+enc.(string))
mime := mimeTypes[enc.(string)]
w.Header().Set("Content-Type", mime)
}
// if response contains an error, write an HTTP error status code