{"record":{"id":"f8943c829609894b","repo":"kataras/iris","slug":"compress-request-is-not-compressed","errorCode":null,"errorMessage":"compress: request is not compressed","messagePattern":"compress: request is not compressed","errorType":"error_code","errorClass":null,"httpStatus":null,"severity":"info","filePath":"context/compress.go","lineNumber":36,"sourceCode":"const (\n\tGZIP    = \"gzip\"\n\tDEFLATE = \"deflate\"\n\tBROTLI  = \"br\"\n\tSNAPPY  = \"snappy\"\n\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}","sourceCodeStart":18,"sourceCodeEnd":54,"githubUrl":"https://github.com/kataras/iris/blob/7bedaf55a0b64bbb2248a5845a2c60d81a30996a/context/compress.go#L18-L54","documentation":"ErrRequestNotCompressed is returned by NewCompressReader when an incoming request is not actually compressed. The caller attempted to create a decompression reader for the request body, but the request's Content-Encoding header indicates no compression. It is a sentinel used to fall back to reading the body as-is.","triggerScenarios":"Calling NewCompressReader (e.g. via ctx.DecompressReader or compression middleware reading the body) when the request's Content-Encoding header is missing, empty, or set to \"identity\".","commonSituations":"A client uploads an uncompressed body while the server unconditionally wraps the body in a decompress reader; misconfigured API clients that forget Content-Encoding: gzip; load balancers or proxies that decompress request bodies upstream and strip the Content-Encoding header.","solutions":["Check the request's Content-Encoding header before creating the reader and only call NewCompressReader when it names a supported encoding.","Handle the sentinel with errors.Is(err, iris.ErrRequestNotCompressed) and read the body uncompressed (ctx.Request().Body).","Fix the sending client to set Content-Encoding (e.g. Content-Encoding: gzip) when it actually compresses the body.","Verify no proxy/load balancer is stripping Content-Encoding from incoming requests."],"exampleFix":"// before\nr, err := ctx.DecompressReader()\nif err != nil { ctx.StopWithStatus(500); return }\n// after\nr, err := ctx.DecompressReader()\nif err != nil {\n    if errors.Is(err, iris.ErrRequestNotCompressed) {\n        r = ctx.Request().Body // read uncompressed body as-is\n    } else {\n        ctx.StopWithStatus(500)\n        return\n    }\n}","handlingStrategy":"fallback","validationCode":"contentEncoding := ctx.GetHeader(\"Content-Encoding\")\nif contentEncoding == \"\" || contentEncoding == \"identity\" {\n    // request body is not compressed; read it directly\n}","typeGuard":"func isCompressedRequest(r *http.Request) bool {\n    ce := r.Header.Get(\"Content-Encoding\")\n    return ce != \"\" && ce != \"identity\"\n}","tryCatchPattern":"r, err := ctx.DecompressReader()\nif err != nil {\n    if errors.Is(err, iris.ErrRequestNotCompressed) {\n        r = ctx.Request().Body // read body uncompressed\n    } else {\n        ctx.StopWithStatus(iris.StatusInternalServerError)\n        return\n    }\n}","preventionTips":["Only wrap the request body in a decompress reader when Content-Encoding names a supported algorithm.","Configure clients to always send Content-Encoding when they compress request bodies.","Check proxies/load balancers that may strip Content-Encoding from requests.","Use errors.Is against the sentinel instead of string-matching the message."],"tags":["http","compression","request-body","encoding"],"backgroundTag":"request-not-compressed","analyzedSha":"7bedaf55a0b64bbb2248a5845a2c60d81a30996a","analyzedAt":"2026-08-30T20:38:16.250Z","schemaVersion":2},"datasetVersion":"2026-08-30T23:17:21.991Z"}