]> Cypherpunks repositories - gostls13.git/commitdiff
net/http: sniff less
authorBrad Fitzpatrick <bradfitz@golang.org>
Tue, 3 Sep 2013 16:11:25 +0000 (09:11 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Tue, 3 Sep 2013 16:11:25 +0000 (09:11 -0700)
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

index 19b493c3755c5ec71692a8d8cbdf677330bbd407..2bcf86baa4a42c41509fc660fa4c46c27630c096 100644 (file)
@@ -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)