From 49be410e055b07e673ee7d5d7d197f3e6ddcbe15 Mon Sep 17 00:00:00 2001 From: Arseny Balobanov Date: Thu, 21 Apr 2022 21:38:22 +0300 Subject: [PATCH] [lectures] Fix content type detection. --- lectures/10-io/sendfile/main.go | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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.