{"record":{"id":"fc8f19d5c148e793","repo":"kataras/iris","slug":"errnotsupportedcompression","errorCode":"ErrNotSupportedCompression","errorMessage":"%w: %s","messagePattern":"%w: %s","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"context/compress.go","lineNumber":58,"sourceCode":"\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}\n\n\treturn encoding, nil\n}\n\ntype (\n\tnoOpWriter struct{}\n\n\tnoOpReadCloser struct {\n\t\tio.Reader\n\t}\n)\n\nvar (\n\t_ io.ReadCloser = (*noOpReadCloser)(nil)\n\t_ io.Writer     = (*noOpWriter)(nil)\n)\n","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/context/compress.go#L40-L76","documentation":"compress.Writer.GetEncoding returns ErrNotSupportedCompression wrapped with the empty/failed encoding when the Accept-Encoding negotiation finds no usable offer. negotiateAcceptHeader scans the client's Accept-Encoding header against the offers and falls back to IDENTITY; if even that match yields an empty string, the error is returned. It is reached from AcquireCompressResponseWriter in the middleware chain.","triggerScenarios":"Calling GetEncoding (via AcquireCompressResponseWriter / the compress middleware) when the client's Accept-Encoding header values cannot be matched to the configured offers and identity negotiation fails. Note the returned 'encoding' interpolated in the message is empty at this point.","commonSituations":"Exotic or malformed Accept-Encoding headers from proxies, crawlers, or API clients; middleware configured with offers that exclude all client-accepted encodings; version changes where IDENTITY fallback stopped matching a 'identity;q=0' style header.","solutions":["Inspect the client's Accept-Encoding header and confirm at least one encoding matches the middleware offers (gzip, deflate, br, snappy, s2).","Check errors.Is(err, compress.ErrNotSupportedCompression) and fall through to serving the response uncompressed instead of failing the request.","Adjust middleware offers to include the encodings your real clients send, or ensure IDENTITY is an accepted fallback.","If a proxy strips or rewrites Accept-Encoding, fix the proxy config or normalize the header server-side."],"exampleFix":"// before\nerr := w.GetEncoding(header.Get(\"Accept-Encoding\")) // returns ErrNotSupportedCompression\n// after\nencoding, err := w.GetEncoding(header.Get(\"Accept-Encoding\"))\nif errors.Is(err, compress.ErrNotSupportedCompression) {\n    // serve identity (uncompressed) response\n    next.ServeHTTP(w, r)\n    return\n}","handlingStrategy":"fallback","validationCode":"ae := r.Header.Get(\"Accept-Encoding\")\nif ae != \"\" && !strings.Contains(ae, \"gzip\") && !strings.Contains(ae, \"deflate\") && !strings.Contains(ae, \"br\") {\n    // client accepts no offered encoding; skip compress middleware\n}","typeGuard":null,"tryCatchPattern":"encoding, err := w.GetEncoding(acceptEncoding)\nif err != nil {\n    if errors.Is(err, compress.ErrNotSupportedCompression) {\n        return \"\", err // caller should serve identity/uncompressed\n    }\n    return \"\", err\n}","preventionTips":["Always include gzip in middleware offers; it is universally supported","Never send 'identity;q=0' style headers from proxies in front of Iris","Treat ErrNotSupportedCompression as expected and fall back to uncompressed responses","Test behind real proxies that may rewrite Accept-Encoding headers"],"tags":["http","compression","accept-encoding","negotiation"],"backgroundTag":"unsupported-encoding","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}