COMPUTER ENGINEER

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

Messages, representations and files

Headers and content negotiation

Separate preferred format from actual format.

UnderstandStudy an examplePractise

Understand the concept

Accept expresses preferred response media types; Content-Type describes the actual body. Requesting JSON does not make a request body JSON. Language and compression preferences have their own fields and must be supported deliberately.

Vary tells caches which request fields distinguish representations. Omitting language from a language-dependent cache key can distribute the wrong translation. Vary: * greatly limits reuse.

Header names are case-insensitive, but value rules are field-specific. Align size limits across clients, proxies and servers. Reject control characters when reflecting untrusted data into fields.

WHEN TO USE IT

Support bilingual representations and diverse clients.

COMMON PITFALL

Interchanging Accept and Content-Type.

01 / PRACTICE

One topic. Three levels of depth.

HTTP / illustrative example
Accept: application/json

Response preference.

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.

Which fields describe a JSON POST body and preferred PDF response?

Show the solution and explanation
Worked solution
Content-Type: application/json
Accept: application/pdf

The server must support the combination; headers do not create support.