Skip to content

Commit df0e1a3

Browse files
gowthamgtsWalter Beegle
authored and
Walter Beegle
committed
ipfs#7252 - read content directly instead of sending 512bytes
1 parent 86aecf1 commit df0e1a3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

core/corehttp/gateway_handler.go

+8-4
Original file line numberDiff line numberDiff line change
@@ -389,12 +389,16 @@ func (i *gatewayHandler) serveFile(w http.ResponseWriter, req *http.Request, nam
389389
} else {
390390
ctype = mime.TypeByExtension(gopath.Ext(name))
391391
if ctype == "" {
392-
buf := make([]byte, 512)
393-
n, _ := io.ReadFull(content, buf[:])
394392
// uses https://github.com/gabriel-vasile/mimetype library to determine the content type.
395393
// Fixes https://github.com/ipfs/go-ipfs/issues/7252
396-
ctype = mimetype.Detect(buf[:n]).String()
397-
_, err := content.Seek(0, io.SeekStart)
394+
mimeType, err := mimetype.DetectReader(content)
395+
if err != nil {
396+
http.Error(w, "cannot detect content-type", http.StatusInternalServerError)
397+
return
398+
}
399+
400+
ctype = mimeType.String()
401+
_, err = content.Seek(0, io.SeekStart)
398402
if err != nil {
399403
http.Error(w, "seeker can't seek", http.StatusInternalServerError)
400404
return

0 commit comments

Comments
 (0)