summaryrefslogtreecommitdiff
path: root/modules/caddyhttp/encode/encode_test.go
diff options
context:
space:
mode:
authordarkweak <darkweak@protonmail.com>2022-12-20 21:26:53 +0100
committerGitHub <noreply@github.com>2022-12-20 13:26:53 -0700
commitdac7cacd4df35e96a4d8c7d09b925bb432509884 (patch)
tree8854735df53b6d0a00050b95cf1ad6fadcbf79ed /modules/caddyhttp/encode/encode_test.go
parentaf93517c2d0e6ad11f8803b59768f0f9d0e11fe1 (diff)
encode: Respect Cache-Control no-transform (#5257)
* encode: respect Cache-Control HTTP header no-transform * encode: switch to strings.Contains
Diffstat (limited to 'modules/caddyhttp/encode/encode_test.go')
-rw-r--r--modules/caddyhttp/encode/encode_test.go47
1 files changed, 47 insertions, 0 deletions
diff --git a/modules/caddyhttp/encode/encode_test.go b/modules/caddyhttp/encode/encode_test.go
index 5f1e3f2..3374ee3 100644
--- a/modules/caddyhttp/encode/encode_test.go
+++ b/modules/caddyhttp/encode/encode_test.go
@@ -261,3 +261,50 @@ func TestValidate(t *testing.T) {
}
}
+
+func TestIsEncodeAllowed(t *testing.T) {
+ testCases := []struct {
+ name string
+ headers http.Header
+ expected bool
+ }{
+ {
+ name: "Without any headers",
+ headers: http.Header{},
+ expected: true,
+ },
+ {
+ name: "Without Cache-Control HTTP header",
+ headers: http.Header{
+ "Accept-Encoding": {"gzip"},
+ },
+ expected: true,
+ },
+ {
+ name: "Cache-Control HTTP header ending with no-transform directive",
+ headers: http.Header{
+ "Accept-Encoding": {"gzip"},
+ "Cache-Control": {"no-cache; no-transform"},
+ },
+ expected: false,
+ },
+ {
+ name: "With Cache-Control HTTP header no-transform as Cache-Extension value",
+ headers: http.Header{
+ "Accept-Encoding": {"gzip"},
+ "Cache-Control": {`no-store; no-cache; community="no-transform"`},
+ },
+ expected: false,
+ },
+ }
+
+ for _, test := range testCases {
+ t.Run(test.name, func(t *testing.T) {
+ if result := isEncodeAllowed(test.headers); result != test.expected {
+ t.Errorf("The headers given to the isEncodeAllowed should return %t, %t given.",
+ result,
+ test.expected)
+ }
+ })
+ }
+}