In this article
Choose the response decoder from the actual content coding and the HTTP library decoding stage.
An inference client receives a successful response and sends its raw bytes to a JSON parser. The parser fails before the first recognizable character, although the same request works in another tool. The tools may differ in automatic content decoding. Inspect Content-Encoding and the library’s behavior before assuming the server returned malformed generation data.
Separate media type from coding
The media type describes the representation format. Content-Encoding describes an additional coding applied to that representation. A JSON media type does not mean the wire bytes begin with a JSON object. Transfer framing is another layer. Write down the decoding order used by the chosen HTTP library and the point at which application code receives bytes, because some libraries transparently remove a coding while preserving selected response headers.
Negotiate only supported decoding
Accept-Encoding advertises content codings the client can handle under the protocol’s selection rules. Build that field from real decoder support. A custom client that manually copies a browser’s header can ask for a coding it cannot decode. Conversely, adding a second decoder around a library that already decompresses can fail on valid plain content. Check the library’s documented automatic-decoding option rather than guessing from how a command-line tool prints the response.
Bound decoded response resources
A small compressed response can expand into a much larger document or event stream. Apply sensible decoded-byte and application-buffer limits in addition to transport limits. For streaming, feed decoded bytes incrementally to the event parser and preserve partial character boundaries. Do not buffer an entire unbounded response merely to simplify decompression. If decoding fails midstream, retain a transport-level failure classification rather than presenting the partial text as a complete successful result.
Reproduce transformations with a fixture
Use a synthetic endpoint that can return the same known content with supported codings and without coding. Compare a digest at the documented stage and verify the parser sees identical logical content. Include an unsupported coding and a truncated compressed body. Test through the production-shaped proxy route in an authorized environment, because the proxy may decode or recode the response before the application receives it. Keep sensitive generated content out of diagnostic dumps.
Inspect whether the library reports encoded or decoded byte counts in progress callbacks. A seemingly impossible expansion in a dashboard may be a difference in measurement stages rather than repeated model output. Label both counters before using them to explain response size or network efficiency.
Fix metadata and behavior together
If an intermediary removes a coding, its outgoing metadata must describe the resulting bytes correctly. If a client advertises unsupported decoding, narrow the request field or add a supported decoder. Acceptance includes correct handling of both coded and uncoded responses, bounded expansion and clear failure on corruption. It does not establish faster inference: compression changes transfer and CPU work, while model execution remains a separate stage. Measure the complete response path before drawing a performance conclusion from fewer wire bytes.
Primary references
HTTP Semantics. Defines Accept-Encoding, Content-Encoding and representation metadata.
HTTP/1.1. Separates transfer framing from representation coding.
Digest Fields. Defines the integrity scope needed to compare coded and decoded content correctly.
Related reading: SSE and UTF-8: a network chunk is not a JSON event; HTTP response integrity: Content-Length, chunked transfer and truncation.
Earn rental income from GPUs
Have idle GPUs or looking to fund AI infrastructure? Retrivium finds a rental platform, sets up the server and helps you assess income and costs with a pilot.