{"record":{"id":"9144064f75d58c6f","repo":"caddyserver/caddy","slug":"encoding-s-is-duplicated-in-prefer","errorCode":null,"errorMessage":"encoding %s is duplicated in prefer","messagePattern":"encoding (.+?) is duplicated in prefer","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/caddyhttp/encode/encode.go","lineNumber":152,"sourceCode":"\t\t\tif _, ok := enc.writerPools[encName]; ok {\n\t\t\t\tenc.Prefer = append(enc.Prefer, encName)\n\t\t\t}\n\t\t}\n\t}\n\n\treturn nil\n}\n\n// Validate ensures that enc's configuration is valid.\nfunc (enc *Encode) Validate() error {\n\tcheck := make(map[string]bool)\n\tfor _, encName := range enc.Prefer {\n\t\tif _, ok := enc.writerPools[encName]; !ok {\n\t\t\treturn fmt.Errorf(\"encoding %s not enabled\", encName)\n\t\t}\n\n\t\tif _, ok := check[encName]; ok {\n\t\t\treturn fmt.Errorf(\"encoding %s is duplicated in prefer\", encName)\n\t\t}\n\t\tcheck[encName] = true\n\t}\n\n\treturn nil\n}\n\nfunc isEncodeAllowed(h http.Header) bool {\n\treturn !strings.Contains(h.Get(\"Cache-Control\"), \"no-transform\")\n}\n\nfunc (enc *Encode) ServeHTTP(w http.ResponseWriter, r *http.Request, next caddyhttp.Handler) error {\n\tif isEncodeAllowed(r.Header) {\n\t\tfor _, encName := range AcceptedEncodings(r, enc.Prefer) {\n\t\t\tif _, ok := enc.writerPools[encName]; !ok {\n\t\t\t\tcontinue // encoding not offered\n\t\t\t}\n\t\t\tw = enc.openResponseWriter(encName, w, r.Method == http.MethodConnect)","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddyhttp/encode/encode.go#L134-L170","documentation":"Validate-time error from encode: the same encoder name appears more than once in the 'prefer' array. The dedup check map detects the second occurrence.","triggerScenarios":"{\"prefer\": [\"zstd\", \"zstd\"]} — a repeated entry in the preference list.","commonSituations":"Config generated by concatenation or copy-paste producing duplicate entries; YAML anchors merging lists with overlap.","solutions":["Remove duplicate entries from the prefer array","If generating config, deduplicate the list before serializing"],"exampleFix":"// before\n\"prefer\": [\"zstd\", \"gzip\", \"zstd\"]\n// after\n\"prefer\": [\"zstd\", \"gzip\"]","handlingStrategy":"validation","validationCode":"// dedupe before writing config\nseen := map[string]bool{}\nout := enc.Prefer[:0]\nfor _, p := range enc.Prefer {\n    if !seen[p] { seen[p] = true; out = append(out, p) }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Deduplicate preference lists in config generators","caddy validate catches this before reload"],"tags":["caddy","encode","config","validation"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}