cmd/ipfs: Added gateway MIME type resolution
Matt Bell committed
Jan 11, 2015 at 21:47 UTC
b5300f1d2747136d8d6a95bd34a0623571647886
1 file changed
+11
cmd/ipfs/gatewayHandler.go
+11
@@ -3,7 +3,9 @@ package main
3
import (
4
"html/template"
5
"io"
6
+ "mime"
7
"net/http"
8
+ "strings"
9
10
"github.com/jbenet/go-ipfs/Godeps/_workspace/src/code.google.com/p/go.net/context"
11
mh "github.com/jbenet/go-ipfs/Godeps/_workspace/src/github.com/jbenet/go-multihash"
@@ -96,6 +98,15 @@ func (i *gatewayHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
98
return
99
}
100
101
+ extensionIndex := strings.LastIndex(path, ".")
102
+ if extensionIndex != -1 {
103
+ extension := path[extensionIndex:]
104
+ mimeType := mime.TypeByExtension(extension)
105
+ if len(mimeType) > 0 {
106
+ w.Header().Add("Content-Type", mimeType)
107
+ }
108
+ }
109
+
110
dr, err := i.NewDagReader(nd)
111
112
if err != nil {