@cryptotaxi247 / kubo / commits / 9201b1dde

#7252 - read content directly instead of sending 512bytes

Gowtham G committed May 1, 2020 at 20:29 UTC 9201b1dde6f994d918825488fa879431bcb7e8b7
1 file changed +8 -4
core/corehttp/gateway_handler.go
+8 -4
@@ -377,12 +377,16 @@ func (i *gatewayHandler) serveFile(w http.ResponseWriter, req *http.Request, nam
377 } else {
378 ctype = mime.TypeByExtension(gopath.Ext(name))
379 if ctype == "" {
380 - buf := make([]byte, 512)
381 - n, _ := io.ReadFull(content, buf[:])
380 // uses https://github.com/gabriel-vasile/mimetype library to determine the content type.
381 // Fixes https://github.com/ipfs/go-ipfs/issues/7252
384 - ctype = mimetype.Detect(buf[:n]).String()
385 - _, err := content.Seek(0, io.SeekStart)
382 + mimeType, err := mimetype.DetectReader(content)
383 + if err != nil {
384 + http.Error(w, "cannot detect content-type", http.StatusInternalServerError)
385 + return
386 + }
387 +
388 + ctype = mimeType.String()
389 + _, err = content.Seek(0, io.SeekStart)
390 if err != nil {
391 http.Error(w, "seeker can't seek", http.StatusInternalServerError)
392 return