{"record":{"id":"aca90f911651a9ea","repo":"kataras/iris","slug":"compress-unsupported-compression","errorCode":null,"errorMessage":"compress: unsupported compression","messagePattern":"compress: unsupported compression","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"context/compress.go","lineNumber":41,"sourceCode":"\tS2      = \"s2\"\n)\n\n// IDENTITY no transformation whatsoever.\nconst IDENTITY = \"identity\"\n\nvar (\n\t// ErrResponseNotCompressed returned from AcquireCompressResponseWriter\n\t// when response's Content-Type header is missing due to golang/go/issues/31753 or\n\t// when accept-encoding is empty. The caller should fallback to the original response writer.\n\tErrResponseNotCompressed = errors.New(\"compress: response will not be compressed\")\n\t// ErrRequestNotCompressed returned from NewCompressReader\n\t// when request is not compressed.\n\tErrRequestNotCompressed = errors.New(\"compress: request is not compressed\")\n\t// ErrNotSupportedCompression returned from\n\t// AcquireCompressResponseWriter, NewCompressWriter and NewCompressReader\n\t// when the request's Accept-Encoding was not found in the server's supported\n\t// compression algorithms. Check that error with `errors.Is`.\n\tErrNotSupportedCompression = errors.New(\"compress: unsupported compression\")\n)\n\n// AllEncodings is a slice of default content encodings.\n// See `AcquireCompressResponseWriter`.\nvar AllEncodings = []string{GZIP, DEFLATE, BROTLI, SNAPPY}\n\n// GetEncoding extracts the best available encoding from the request.\nfunc GetEncoding(r *http.Request, offers []string) (string, error) {\n\tacceptEncoding := r.Header[AcceptEncodingHeaderKey]\n\n\tif len(acceptEncoding) == 0 {\n\t\treturn \"\", ErrResponseNotCompressed\n\t}\n\n\tencoding := negotiateAcceptHeader(acceptEncoding, offers, IDENTITY)\n\tif encoding == \"\" {\n\t\treturn \"\", fmt.Errorf(\"%w: %s\", ErrNotSupportedCompression, encoding)\n\t}","sourceCodeStart":23,"sourceCodeEnd":59,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/context/compress.go#L23-L59","documentation":"ErrNotSupportedCompression is returned by GetEncoding, AcquireCompressResponseWriter, NewCompressWriter and NewCompressReader when the encoding named in the client's Accept-Encoding (or the requested encoding) is not among the server's configured/supported algorithms (by default GZIP, DEFLATE, BROTLI, SNAPPY). The docs advise checking it with errors.Is. It indicates a negotiation mismatch between client and server.","triggerScenarios":"A request advertises Accept-Encoding (or Content-Encoding for readers) with an algorithm not in the server's configured encoding list, e.g. zstd when the server only has gzip/deflate/brotli/snappy; or AcquireCompressResponseWriter is called with an explicit encoding string that is not registered.","commonSituations":"Clients sending modern encodings like zstd or br when the server was configured with only gzip; custom AllEncodings/encodings option that omits an algorithm a client requests; version changes where a previously available algorithm is not configured; typo in a custom encoding string.","solutions":["Add the missing algorithm to the server's supported encodings (e.g. compress.New with encodings including the one clients send) or to AllEncodings.","Check with errors.Is(err, iris.ErrNotSupportedCompression) and respond with an identity (uncompressed) response or 406.","Align client Accept-Encoding with the server's supported list (e.g. request only gzip).","Register the matching compressor (e.g. import the brotli/snappy child package) so the algorithm is actually available."],"exampleFix":"// before\nenc, err := iris.GetEncoding(ctx.GetHeader(\"Accept-Encoding\")) // zstd -> ErrNotSupportedCompression\n// after\nclientEnc := ctx.GetHeader(\"Accept-Encoding\")\nenc, err := iris.GetEncoding(clientEnc)\nif errors.Is(err, iris.ErrNotSupportedCompression) {\n    clientEnc = iris.IDENTITY // fall back to no compression\n    enc, err = iris.GetEncoding(clientEnc)\n}","handlingStrategy":"validation","validationCode":"encodings := iris.AllEncodings // GZIP, DEFLATE, BROTLI, SNAPPY\nclientEnc := ctx.GetHeader(\"Accept-Encoding\")\nfor _, e := range encodings {\n    if strings.Contains(clientEnc, e) {\n        // supported, safe to negotiate\n        break\n    }\n}","typeGuard":"func isSupportedEncoding(enc string) bool {\n    for _, e := range iris.AllEncodings {\n        if strings.EqualFold(e, enc) {\n            return true\n        }\n    }\n    return false\n}","tryCatchPattern":"enc, err := iris.GetEncoding(ctx.GetHeader(\"Accept-Encoding\"))\nif err != nil {\n    if errors.Is(err, iris.ErrNotSupportedCompression) {\n        // respond identity/uncompressed or 406 Not Acceptable\n    } else {\n        ctx.StopWithStatus(iris.StatusInternalServerError)\n        return\n    }\n}","preventionTips":["Keep the server's configured encoding list in sync with what your clients actually send.","Register every compressor you advertise (import the corresponding child packages).","Avoid typos in custom encoding strings; prefer the library constants (GZIP, DEFLATE, BROTLI, SNAPPY).","Always check with errors.Is, as the docs explicitly recommend."],"tags":["http","compression","content-negotiation","encoding"],"backgroundTag":"unsupported-encoding","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}