From 8272c14f7e70fef1dd102e10936577d5156d649f Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 3 Sep 2013 09:11:25 -0700 Subject: [PATCH] net/http: sniff less We were reading 1024 bytes but only using 512. Fixes #6311 R=golang-dev, iant CC=golang-dev https://golang.org/cl/13289047 --- src/pkg/net/http/fs.go | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/pkg/net/http/fs.go b/src/pkg/net/http/fs.go index 19b493c375..2bcf86baa4 100644 --- a/src/pkg/net/http/fs.go +++ b/src/pkg/net/http/fs.go @@ -146,10 +146,9 @@ func serveContent(w ResponseWriter, r *Request, name string, modtime time.Time, ctype = mime.TypeByExtension(filepath.Ext(name)) if ctype == "" { // read a chunk to decide between utf-8 text and binary - var buf [1024]byte + var buf [sniffLen]byte n, _ := io.ReadFull(content, buf[:]) - b := buf[:n] - ctype = DetectContentType(b) + ctype = DetectContentType(buf[:n]) _, err := content.Seek(0, os.SEEK_SET) // rewind to output whole file if err != nil { Error(w, "seeker can't seek", StatusInternalServerError) -- 2.50.0