From b8f729b88fccfd4d5178269df62a56722a37b5d4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Sun, 4 Feb 2024 23:28:37 +0100 Subject: [PATCH 1/4] fix: add more media types to the compressed by default list --- modules/caddyhttp/encode/encode.go | 50 +++++++++++++++++++++++++++--- 1 file changed, 46 insertions(+), 4 deletions(-) diff --git a/modules/caddyhttp/encode/encode.go b/modules/caddyhttp/encode/encode.go index 8f733a3f..7fce7336 100644 --- a/modules/caddyhttp/encode/encode.go +++ b/modules/caddyhttp/encode/encode.go @@ -84,17 +84,59 @@ func (enc *Encode) Provision(ctx caddy.Context) error { if enc.Matcher == nil { // common text-based content types + // list based on https://developers.cloudflare.com/speed/optimization/content/brotli/content-compression/#compression-between-cloudflare-and-website-visitors + // with application/atom+rss added enc.Matcher = &caddyhttp.ResponseMatcher{ Headers: http.Header{ "Content-Type": []string{ - "text/*", - "application/json*", - "application/javascript*", - "application/xhtml+xml*", "application/atom+xml*", + "application/eot*", + "application/font*", + "application/font-sfnt*", + "application/font-woff*", + "application/geo+json*", + "application/graphql+json*", + "application/javascript*", + "application/javascript-binast*", + "application/json*", + "application/ld+json*", + "application/manifest+json*", + "application/opentype*", + "application/otf*", "application/rss+xml*", + "application/truetype*", + "application/ttf*", + "application/vnd.api+json*", + "application/vnd.ms-fontobject*", "application/wasm*", + "application/x-httpd-cgi*", + "application/x-javascript*", + "application/x-opentype*", + "application/x-otf*", + "application/x-perl*", + "application/x-protobuf*", + "application/x-ttf*", + "application/xhtml+xml*", + "application/xml*", + "font/otf*", + "font/ttf*", + "font/x-woff*", "image/svg+xml*", + "image/vnd.microsoft.icon*", + "image/x-icon*", + "multipart/bag*", + "multipart/mixed*", + "text/css*", + "text/javascript*", + "text/js*", + "text/plain*", + "text/richtext*", + "text/x-component*", + "text/x-java-source*", + "text/x-markdown*", + "text/x-script*", + "text/xml*", + "text/html*", }, }, } From 60abd72c7ab1c90a52fcc079186046910731dc7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Mon, 5 Feb 2024 08:29:43 +0100 Subject: [PATCH 2/4] fix: add back text/* --- modules/caddyhttp/encode/encode.go | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/modules/caddyhttp/encode/encode.go b/modules/caddyhttp/encode/encode.go index 7fce7336..d9e07696 100644 --- a/modules/caddyhttp/encode/encode.go +++ b/modules/caddyhttp/encode/encode.go @@ -126,17 +126,7 @@ func (enc *Encode) Provision(ctx caddy.Context) error { "image/x-icon*", "multipart/bag*", "multipart/mixed*", - "text/css*", - "text/javascript*", - "text/js*", - "text/plain*", - "text/richtext*", - "text/x-component*", - "text/x-java-source*", - "text/x-markdown*", - "text/x-script*", - "text/xml*", - "text/html*", + "text/*", }, }, } From d3f23a8eeb3b0b7198ae4c06879227b467fcfaa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 6 Feb 2024 01:35:17 +0100 Subject: [PATCH 3/4] improved list --- modules/caddyhttp/encode/encode.go | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/modules/caddyhttp/encode/encode.go b/modules/caddyhttp/encode/encode.go index d9e07696..c950d12d 100644 --- a/modules/caddyhttp/encode/encode.go +++ b/modules/caddyhttp/encode/encode.go @@ -92,12 +92,9 @@ func (enc *Encode) Provision(ctx caddy.Context) error { "application/atom+xml*", "application/eot*", "application/font*", - "application/font-sfnt*", - "application/font-woff*", "application/geo+json*", "application/graphql+json*", "application/javascript*", - "application/javascript-binast*", "application/json*", "application/ld+json*", "application/manifest+json*", @@ -118,9 +115,7 @@ func (enc *Encode) Provision(ctx caddy.Context) error { "application/x-ttf*", "application/xhtml+xml*", "application/xml*", - "font/otf*", - "font/ttf*", - "font/x-woff*", + "font/*", "image/svg+xml*", "image/vnd.microsoft.icon*", "image/x-icon*", From 2348ac897a63fb7b37783bb1540b00eeb8f25e22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dunglas?= Date: Tue, 6 Feb 2024 01:35:39 +0100 Subject: [PATCH 4/4] update comment --- modules/caddyhttp/encode/encode.go | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/caddyhttp/encode/encode.go b/modules/caddyhttp/encode/encode.go index c950d12d..bd3d84bc 100644 --- a/modules/caddyhttp/encode/encode.go +++ b/modules/caddyhttp/encode/encode.go @@ -85,7 +85,6 @@ func (enc *Encode) Provision(ctx caddy.Context) error { if enc.Matcher == nil { // common text-based content types // list based on https://developers.cloudflare.com/speed/optimization/content/brotli/content-compression/#compression-between-cloudflare-and-website-visitors - // with application/atom+rss added enc.Matcher = &caddyhttp.ResponseMatcher{ Headers: http.Header{ "Content-Type": []string{