From e294e109f80fadb183dee2da329e587e8a9b3bd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Sun, 16 Apr 2017 01:37:26 +0200 Subject: [PATCH] Handle requests with no Accept-Encoding properly --- server/serve_files.go | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/server/serve_files.go b/server/serve_files.go index b119e8a8..901e6343 100644 --- a/server/serve_files.go +++ b/server/serve_files.go @@ -274,16 +274,14 @@ func serveFile(w http.ResponseWriter, r *http.Request, file *File) { w.Header().Set("Content-Type", file.ContentType) - if file.Compressed { - if strings.Contains(r.Header.Get("Accept-Encoding"), "br") { - w.Header().Set("Content-Encoding", "br") - w.Header().Set("Content-Length", strconv.Itoa(len(data))) - w.Write(data) - } else if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { - w.Header().Set("Content-Encoding", "gzip") - w.Header().Set("Content-Length", strconv.Itoa(len(file.GzipAsset))) - w.Write(file.GzipAsset) - } + if file.Compressed && strings.Contains(r.Header.Get("Accept-Encoding"), "br") { + w.Header().Set("Content-Encoding", "br") + w.Header().Set("Content-Length", strconv.Itoa(len(data))) + w.Write(data) + } else if file.Compressed && strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { + w.Header().Set("Content-Encoding", "gzip") + w.Header().Set("Content-Length", strconv.Itoa(len(file.GzipAsset))) + w.Write(file.GzipAsset) } else if !file.Compressed { w.Header().Set("Content-Length", strconv.Itoa(len(data))) w.Write(data)