{"record":{"id":"eecb110f4130a1b8","repo":"caddyserver/caddy","slug":"encoder-does-not-specify-an-accept-encoding-value","errorCode":null,"errorMessage":"encoder does not specify an Accept-Encoding value","messagePattern":"encoder does not specify an Accept-Encoding value","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"modules/caddyhttp/encode/encode.go","lineNumber":206,"sourceCode":"\t\t}\n\t}\n\n\terr := next.ServeHTTP(w, r)\n\t// If there was an error, disable encoding completely\n\t// This prevents corruption when handle_errors processes the response\n\tif err != nil {\n\t\tif ew, ok := w.(*responseWriter); ok {\n\t\t\tew.disabled = true\n\t\t}\n\t}\n\n\treturn err\n}\n\nfunc (enc *Encode) addEncoding(e Encoding) error {\n\tae := e.AcceptEncoding()\n\tif ae == \"\" {\n\t\treturn fmt.Errorf(\"encoder does not specify an Accept-Encoding value\")\n\t}\n\tif _, ok := enc.writerPools[ae]; ok {\n\t\treturn fmt.Errorf(\"encoder already added: %s\", ae)\n\t}\n\tif enc.writerPools == nil {\n\t\tenc.writerPools = make(map[string]*sync.Pool)\n\t}\n\tenc.writerPools[ae] = &sync.Pool{\n\t\tNew: func() any {\n\t\t\treturn e.NewEncoder()\n\t\t},\n\t}\n\treturn nil\n}\n\n// openResponseWriter creates a new response writer that may (or may not)\n// encode the response with encodingName. The returned response writer MUST\n// be closed after the handler completes.","sourceCodeStart":188,"sourceCodeEnd":224,"githubUrl":"https://github.com/caddyserver/caddy/blob/50e54ee279aa1e504fe218ca49ab6ae16c100410/modules/caddyhttp/encode/encode.go#L188-L224","documentation":"Returned by Encode.addEncoding when an Encoding implementation's AcceptEncoding() returns an empty string. The Accept-Encoding token is used as the pool key and for client negotiation, so an empty value makes the encoder unusable.","triggerScenarios":"Any custom encoder module whose AcceptEncoding() method returns \"\" being loaded during encode provisioning.","commonSituations":"Plugin authors implementing encode.Encoding but forgetting or stubbing AcceptEncoding().","solutions":["Implement AcceptEncoding() to return a valid, unique token like \"br\" or \"myzip\"","Register the token with IANA-style naming and keep it consistent with what clients send"],"exampleFix":"// before\nfunc (E) AcceptEncoding() string { return \"\" }\n// after\nfunc (E) AcceptEncoding() string { return \"myzip\" }","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"// compile-time: your encoder satisfies the full contract\nvar _ encode.Encoding = (*MyEncoding)(nil)","tryCatchPattern":null,"preventionTips":["Always implement AcceptEncoding() with a unique token","Unit-test plugin encoders through encode.Encode provisioning"],"tags":["caddy","encode","plugin","api-contract"],"backgroundTag":null,"analyzedSha":"50e54ee279aa1e504fe218ca49ab6ae16c100410","analyzedAt":"2026-08-15T09:20:21.641Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}