COMPUTER ENGINEER

Jump to examples
Blog
HTTP / HTTPS / TLS6 min study
21/ 70

Messages, representations and files

Content-Length, compression and framing

Byte count is not character count.

UnderstandStudy an examplePractise

Understand the concept

Content-Length counts transferred body bytes, not characters. UTF-8 characters can occupy several bytes. Content-Encoding describes transformations such as gzip/br, while Content-Type describes media format. Compressed and decoded lengths differ.

HTTP/1.1 chunking can transfer a body without knowing its final length. HTTP/2 and HTTP/3 use their own framing rather than chunked Transfer-Encoding. Intermediaries must agree on message boundaries; conflicting framing fields can create parsing and security failures. Use maintained protocol implementations.

Compression trades CPU for bandwidth and may add little value for small or already-compressed content. Compressing secrets beside attacker-controlled data can introduce side channels. Smaller payloads are not evidence of security.

WHEN TO USE IT

Diagnose truncation, size mismatches and intermediary issues.

COMMON PITFALL

Using character length as Content-Length.

01 / PRACTICE

One topic. Three levels of depth.

HTTP / illustrative example
Content-Type: text/plain; charset=utf-8

Account for UTF-8 byte length.

This page does not send requests to external servers. Messages are readable HTTP/1.1 illustrations, not HTTP/2 or HTTP/3 wire dumps. example.test is reserved for examples. Run commands and JavaScript only in your own test environment; never publish real tokens or cookies.

02 / YOUR TURN

Try it yourself first.

Must decoded gzip content equal Content-Length?

Show the solution and explanation
Worked solution
Transferred bytes ≠ decoded bytes

No; transfer size and decoded size are different measurements.