Skip to content

Commit

Permalink
ipfs#7252 - read content directly instead of sending 512bytes
Browse files Browse the repository at this point in the history
  • Loading branch information
gowthamgts authored and Walter Beegle committed Jun 6, 2020
1 parent 86aecf1 commit df0e1a3
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions core/corehttp/gateway_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -389,12 +389,16 @@ func (i *gatewayHandler) serveFile(w http.ResponseWriter, req *http.Request, nam
} else {
ctype = mime.TypeByExtension(gopath.Ext(name))
if ctype == "" {
buf := make([]byte, 512)
n, _ := io.ReadFull(content, buf[:])
// uses https://github.com/gabriel-vasile/mimetype library to determine the content type.
// Fixes https://github.com/ipfs/go-ipfs/issues/7252
ctype = mimetype.Detect(buf[:n]).String()
_, err := content.Seek(0, io.SeekStart)
mimeType, err := mimetype.DetectReader(content)
if err != nil {
http.Error(w, "cannot detect content-type", http.StatusInternalServerError)
return
}

ctype = mimeType.String()
_, err = content.Seek(0, io.SeekStart)
if err != nil {
http.Error(w, "seeker can't seek", http.StatusInternalServerError)
return
Expand Down

0 comments on commit df0e1a3

Please sign in to comment.