Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 55 additions & 3 deletions response/gzip/middleware.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@
return rw.Write(data)
}

func (rw *gzipResponseWriter) writeHeader(statusCode int) {
func (rw *gzipResponseWriter) writeHeader(statusCode int) { //nolint:funlen
if rw.headersWritten {
return
}
Expand All @@ -166,8 +166,60 @@
h := rw.Header()
ct := h.Get(contentTypeHeader)

if ct == "image/jpeg" || ct == "image/png" || ct == "image/webp" || ct == "image/gif" {
rw.disableCompression = true
// See https://developers.cloudflare.com/speed/optimization/content/brotli/content-compression/.
switch ct {
case "",
"text/html",
"text/richtext",
"text/plain",
"text/css",
"text/x-script",
"text/x-component",
"text/x-java-source",
"text/x-markdown",
"application/javascript",
"application/x-javascript",
"text/javascript",
"text/js",
"image/x-icon",
"image/vnd.microsoft.icon",
"application/x-perl",
"application/x-httpd-cgi",
"text/xml",
"application/xml",
"application/rss+xml",
"application/vnd.api+json",
"application/x-protobuf",
"application/json",
"multipart/bag",
"multipart/mixed",
"application/xhtml+xml",
"font/ttf",
"font/otf",
"font/x-woff",
"image/svg+xml",
"application/vnd.ms-fontobject",
"application/ttf",
"application/x-ttf",
"application/otf",
"application/x-otf",
"application/truetype",
"application/opentype",
"application/x-opentype",
"application/font-woff",
"application/eot",
"application/font",
"application/font-sfnt",
"application/wasm",
"application/javascript-binast",
"application/manifest+json",
"application/ld+json",
"application/graphql+json",
"application/geo+json":
default:
if !strings.HasSuffix(ct, "+json") {
rw.disableCompression = true
}

Check notice on line 222 in response/gzip/middleware.go

View workflow job for this annotation

GitHub Actions / test (1.22.x)

2 statement(s) are not covered by tests.
}

if h.Get(contentEncodingHeader) != "" || rw.disableCompression {
Expand Down
Loading