diff --git a/lectures/10-io/sendfile/main.go b/lectures/10-io/sendfile/main.go index b4eccd9..80867a4 100644 --- a/lectures/10-io/sendfile/main.go +++ b/lectures/10-io/sendfile/main.go @@ -39,8 +39,7 @@ func copyHandler(w http.ResponseWriter, r *http.Request) { defer func() { _ = f.Close() }() // Infer the Content-Type of the file. - filePrefix := make([]byte, 1024) - _, _ = io.ReadAtLeast(f, filePrefix, 512) + filePrefix, _ := io.ReadAll(io.LimitReader(f, 512)) contentType := http.DetectContentType(filePrefix) // Get the file size.