{"record":{"id":"b5645bbeeb080dc0","repo":"valyala/fasthttp","slug":"fasthttp-unsupported-transfer-encoding","errorCode":null,"errorMessage":"fasthttp: unsupported transfer-encoding","messagePattern":"fasthttp: unsupported transfer-encoding","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"header.go","lineNumber":479,"sourceCode":"// 6. determining how to process the payload (e.g., Content-Encoding, Content-Type, Content-Range, and Trailer)\n//\n// Return ErrBadTrailer if contain any forbidden trailers.\nfunc (h *header) AddTrailer(trailer string) error {\n\treturn h.AddTrailerBytes(s2b(trailer))\n}\n\nvar (\n\tErrBadTrailer                    = errors.New(\"fasthttp: contain forbidden trailer\")\n\tErrReadingResponseHeaders        = errors.New(\"fasthttp: error when reading response headers\")\n\tErrReadingResponseTrailer        = errors.New(\"fasthttp: error when reading response trailer\")\n\tErrResponseFirstLineMissingSpace = errors.New(\"fasthttp: cannot find whitespace in the first line of response\")\n\tErrUnexpectedStatusCodeChar      = errors.New(\"fasthttp: unexpected char at the end of status code\")\n\tErrMissingRequestMethod          = errors.New(\"fasthttp: cannot find http request method\")\n\tErrUnsupportedRequestMethod      = errors.New(\"fasthttp: unsupported http request method\")\n\tErrExtraWhitespaceInRequestLine  = errors.New(\"fasthttp: extra whitespace in request line\")\n\tErrEmptyRequestURI               = errors.New(\"fasthttp: requesturi cannot be empty\")\n\tErrDuplicateContentLength        = errors.New(\"fasthttp: duplicate content-length header\")\n\tErrUnsupportedTransferEncoding   = errors.New(\"fasthttp: unsupported transfer-encoding\")\n\tErrNonNumericChars               = errors.New(\"fasthttp: non-numeric chars found\")\n\tErrNeedMore                      = errors.New(\"fasthttp: need more data: cannot find trailing lf\")\n\tErrSmallReadBuffer               = errors.New(\"fasthttp: small read buffer. increase readbuffersize\")\n)\n\n// AddTrailerBytes add Trailer header value for chunked response\n// to indicate which headers will be sent after the body.\n//\n// Use Set to set the trailer header later.\n//\n// Trailers are only supported with chunked transfer.\n// Trailers allow the sender to include additional headers at the end of chunked messages.\n//\n// The following trailers are forbidden:\n// 1. necessary for message framing (e.g., Transfer-Encoding and Content-Length),\n// 2. routing (e.g., Host),\n// 3. request modifiers (e.g., controls and conditionals in Section 5 of [RFC7231]),\n// 4. authentication (e.g., see [RFC7235] and [RFC6265]),","sourceCodeStart":461,"sourceCodeEnd":497,"githubUrl":"https://github.com/valyala/fasthttp/blob/c96f600972c6f4a7a30d664257b340ebe9d60124/header.go#L461-L497","documentation":"fasthttp supports only specific Transfer-Encoding values (chiefly 'chunked' or identity/none). When a parsed message carries an unsupported Transfer-Encoding header value, ErrUnsupportedTransferEncoding is returned. This prevents ambiguous body framing that could break streaming or enable smuggling.","triggerScenarios":"Request/Response Read on headers like 'Transfer-Encoding: gzip, chunked' (multi-coding) or 'Transfer-Encoding: deflate'; setting h.SetTransferEncoding to a non-chunked value; proxies that convert content-encoding into transfer-encoding incorrectly.","commonSituations":"Upstream gateways emitting 'Transfer-Encoding: gzip' instead of Content-Encoding: gzip; custom clients sending exotic transfer codings; compression middleware misconfigured on the sending side.","solutions":["Make the sender use 'Transfer-Encoding: chunked' for streaming bodies or plain Content-Length framing otherwise.","If the intent was compression, move it to 'Content-Encoding: gzip' and keep Transfer-Encoding as chunked.","Remove the header entirely when body framing is Content-Length based: h.Del(\"Transfer-Encoding\").","Update the intermediate proxy/middleware that emits the unsupported value."],"exampleFix":"// before\nw.Header(\"Transfer-Encoding\", \"gzip\") // unsupported coding\n// after\nw.Header(\"Content-Encoding\", \"gzip\")\n// (body still chunked or Content-Length framed)","handlingStrategy":"validation","validationCode":"te := string(req.Header.Peek(\"Transfer-Encoding\"))\nt := strings.ToLower(strings.TrimSpace(te))\nif t != \"\" && t != \"chunked\" {\n    return fmt.Errorf(\"unsupported transfer-encoding %q\", te)\n}","typeGuard":"func isUnsupportedTransferEncoding(err error) bool {\n    return err == fasthttp.ErrUnsupportedTransferEncoding\n}","tryCatchPattern":"if err := client.Do(req, resp); err == fasthttp.ErrUnsupportedTransferEncoding {\n    return fmt.Errorf(\"peer uses unsupported transfer-encoding: %w\", err)\n}","preventionTips":["Use only chunked (or no) Transfer-Encoding with fasthttp; keep compression in Content-Encoding.","Fix middleware/proxies that write encoding names (gzip) into Transfer-Encoding.","Delete the header when Content-Length framing is used instead.","Document framing rules for teams building senders against your fasthttp service."],"tags":["http","fasthttp","header-parsing","transfer-encoding"],"backgroundTag":"unsupported-transfer-encoding","analyzedSha":"c96f600972c6f4a7a30d664257b340ebe9d60124","analyzedAt":"2026-08-31T22:48:28.265Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T05:18:18.240Z"}