Content negotiation
05The caller can express preferences for media type, language, or coding; the server chooses a representation.
The response metadata describes what actually arrived.
Key idea: Negotiate a representation and describe the choice.
Terms
- Client / user agent
- The app making a request; in this example, your browser.
- Origin server
- The server responsible for providing an answer for the target resource.
- Request
- A message asking for an action on a resource.
- Response
- The server’s message reporting the result of a request.
- Resource
- Something identified by a URI, such as the page at /story.
- Representation
- Content and descriptive information that convey a resource’s state, such as an HTML page.
- Semantics
- What a message or protocol element means, independently of how it travels.
- Content negotiation
- Choosing a representation using preferences and available alternatives.
- Accept
- A request field listing preferred media types.
- q value
- A relative preference weight; it does not guarantee the server’s choice.
- Vary
- A response field identifying request fields that influenced representation selection.
Rules & examples
Negotiate a representation and describe the choice.
- Accept, Accept-Language, and Accept-Encoding express client preferences; q values express relative weights.
- Proactive negotiation selects before the response; reactive negotiation offers choices for a later request.
- Vary identifies request fields that influenced selection so caches can distinguish variants.
Preferences do not guarantee a particular result. The server can sometimes disregard them or return a negotiation failure. Accept-Charset is deprecated.
Predict: Does Accept guarantee that the server will return your preferred format?
Check your answer
No. Preferences guide selection; they do not guarantee a particular result.
Sources
New to this? Start hereA quick picture + helpful background
A request starts a conversation.
A client asks for a resource. A server sends a response. The method, address, headers, and status explain what that conversation means.
Helpful first, if these ideas are unfamiliar
These pictures are analogies to help you learn. The linked RFC explains the actual rules.
Related RFCs and changes
“Updates” changes part of an earlier RFC. “Obsoletes” replaces it. This list shows selected related documents.
Accept-Charset is now deprecated. Appendix B.3 lists this change; senders should not use it as a modern charset-negotiation mechanism.
Read the updated RFC section ↗