From 2d1170f158e0599026a350e2db3c2ed691ed0876 Mon Sep 17 00:00:00 2001 From: bel Date: Sun, 7 May 2023 19:34:42 -0600 Subject: [PATCH] dont gzip a gzip and .js.gz has contenttype javascript --- contenttype.go | 3 +++ gzipresponsewriter.go | 3 +++ 2 files changed, 6 insertions(+) diff --git a/contenttype.go b/contenttype.go index 13f244d..ef00adb 100755 --- a/contenttype.go +++ b/contenttype.go @@ -82,6 +82,9 @@ func SetContentTypeIfMedia(w http.ResponseWriter, r *http.Request) { case ".gz": w.Header().Set("Content-Encoding", "gzip") v = "application/gzip" + if path.Ext(r.URL.Path) == ".js.gz" { + v = "application/javascript" + } case ".gif": v = "image/gif" case ".htm,": diff --git a/gzipresponsewriter.go b/gzipresponsewriter.go index 05467be..6947cf0 100755 --- a/gzipresponsewriter.go +++ b/gzipresponsewriter.go @@ -12,6 +12,9 @@ type GZipResponseWriter struct { } func Can(r *http.Request) bool { + if strings.HasSuffix(r.URL.Path, ".gz") { + return false + } encodings, _ := r.Header["Accept-Encoding"] for _, encoding := range encodings { items := strings.Split(encoding, ",")