From 714e13b63a808eb9b0babef2768dab7e04809a47 Mon Sep 17 00:00:00 2001 From: Matt Bell Date: Tue, 28 Oct 2014 19:31:23 -0700 Subject: [PATCH] commands/http: Explicitly define the MIME types for each encoding --- commands/http/handler.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/commands/http/handler.go b/commands/http/handler.go index 3db13e79a..222a792d6 100644 --- a/commands/http/handler.go +++ b/commands/http/handler.go @@ -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