@cryptotaxi247 / kubo / commits / 714e13b63

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

Matt Bell committed Oct 28, 2014 at 19:31 UTC 714e13b63a808eb9b0babef2768dab7e04809a47
1 file changed +8 -2
commands/http/handler.go
+8 -2
@@ -15,6 +15,12 @@ type Handler struct {
15
16 var ErrNotFound = errors.New("404 page not found")
17
18 +var mimeTypes = map[string]string{
19 + cmds.JSON: "application/json",
20 + cmds.XML: "application/xml",
21 + cmds.Text: "text/plain",
22 +}
23 +
24 func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
25 req, err := Parse(r)
26 if err != nil {
@@ -36,9 +42,9 @@ func (i Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
42 // TODO: set based on actual Content-Type of file
43 w.Header().Set("Content-Type", "application/octet-stream")
44 } else {
39 - // TODO: get proper MIME type for encoding from multicodec lib
45 enc, _ := req.Option(cmds.EncShort)
41 - w.Header().Set("Content-Type", "application/"+enc.(string))
46 + mime := mimeTypes[enc.(string)]
47 + w.Header().Set("Content-Type", mime)
48 }
49
50 // if response contains an error, write an HTTP error status code