MCPcopy
hub / github.com/caddyserver/caddy / TestIsEncodeAllowed

Function TestIsEncodeAllowed

modules/caddyhttp/encode/encode_test.go:258–303  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

256}
257
258func TestIsEncodeAllowed(t *testing.T) {
259 testCases := []struct {
260 name string
261 headers http.Header
262 expected bool
263 }{
264 {
265 name: "Without any headers",
266 headers: http.Header{},
267 expected: true,
268 },
269 {
270 name: "Without Cache-Control HTTP header",
271 headers: http.Header{
272 "Accept-Encoding": {"gzip"},
273 },
274 expected: true,
275 },
276 {
277 name: "Cache-Control HTTP header ending with no-transform directive",
278 headers: http.Header{
279 "Accept-Encoding": {"gzip"},
280 "Cache-Control": {"no-cache; no-transform"},
281 },
282 expected: false,
283 },
284 {
285 name: "With Cache-Control HTTP header no-transform as Cache-Extension value",
286 headers: http.Header{
287 "Accept-Encoding": {"gzip"},
288 "Cache-Control": {`no-store; no-cache; community="no-transform"`},
289 },
290 expected: false,
291 },
292 }
293
294 for _, test := range testCases {
295 t.Run(test.name, func(t *testing.T) {
296 if result := isEncodeAllowed(test.headers); result != test.expected {
297 t.Errorf("The headers given to the isEncodeAllowed should return %t, %t given.",
298 result,
299 test.expected)
300 }
301 })
302 }
303}
304
305type mockEncoder struct{}
306

Callers

nothing calls this directly

Calls 1

isEncodeAllowedFunction · 0.85

Tested by

no test coverage detected