HTTP Content Negotiation
Most of the responses of HTTP include an entity which contains the information for interpretation by a user. Naturally, it is used to supply the user with the best available entity corresponding to the request. Unfortunately for cache and server, not all users have the same preferences for what is best. That’s why HTTP has provisions for several mechanisms for “content negotiation“. When there are multiple representations available, the process of selecting the best representation for a given response.
Any response which contains an entity-body MAY be subject to negotiation, including error responses.
In HTTP, there are two types of content negotiation, server-driven negotiation, and agent-driven negotiation. Both the negotiations are orthogonal and thus may be used in combination or separately. One method of combination referred to as transparent negotiation which occurs when the origin server provides the information of agent-driven negotiation, which is used by the cache to provide server-driven negotiation for subsequent requests.
When a server-driven negotiation occurs, then the selection of the best representation for a response is made by an algorithm which is located at the server. Based on the available representation of a resource, the selection is based, and the contents. Selection is also based on contents of particular header fields in the request message or on other information, which is pretending to the request (like the network address of the client).
- It is useful when the algorithm for selecting from among the available representations is difficult to describe to the user agent.
- It is useful when the server desires to send its “best guess” to the client along with the first response.
- To improve the guess of the server, the user agent may include request header fields that describe its preferences for such a response.
- For the server, it is impossible to determine what might be best for any given user accurately. That’s why the server would need complete knowledge of both the capabilities of the user agent and the intended use for the response.
- It complicates an origin server implementation and the algorithms for generating responses to a request.
When an agent-driven negotiation occurs, the user agent performs the selection of the best representation for a response after receiving an initial response from the origin server. In agent-driven negotiation, the selection is based on a list of available representations of the response, which is included within the header fields or entity-body of the initial response, with each representation identified by its own URI. Selection from a list of representations may be performed manually by the user selection from a generated menu or automatically.
- It is used when the response would vary over commonly-used dimensions when the origin server is unable to determine the capability of a user agent from examining the request.
- It is used when public caches distribute server load and reduce network usage.
An agent-driven negotiation suffers when it needs a second request to obtain the best alternate representation.
It is a combination of both server-driven negotiation and agent-driven negotiation. If a cache is supplied in the form of a list of available representations of the response and cache completely understood the variance’s dimension, then the cache becomes capable of performing server-driven negotiation on behalf of the origin server.