Learn something new every day
More Info... by email
Content negotiation is a technique described in the hyptertext transfer protocol (HTTP) specification that allows a remote client to make a more specific request of a web server. The method gives the server the ability to host multiple types of files, documents in different languages, and more, each with varying quality levels. These separate selections are hosted as a single reference, denoted by its uniform resource identifier (URI), and are meant to provide more applicable content when it's available on the server.
Where a uniform resource locator (URL) is a reference to a file in a specific location, such as within a folder on the server, a URI can reference anything, virtually anywhere. The specifics of the URI, such as the location of the file to be delivered, the name of the file, and its type, are worked out after the content is negotiated. This allows for the various pieces of content to sit in different locations, such as all of the files for a certain language organized under that language's folder on the server.
The idea behind content negotiation is for the web server to deliver the best possible content for any given user agent or web browser. It can deliver certain image file types or other content to clients that are capable of supporting them. This is useful when hosting multiple versions of a file to support multiple browsing platforms, such as mobile devices.
To do all this, the HTTP describes two methods of content negotiation, as well as suggests the ability to combine the two. One method is server-driven negotiation. With this method, the server makes the best possible decision on what to deliver, based on whatever logic it is given, and what content is available. .
There are some difficulties with server-driven content negotiation, however. The server doesn't know how to respond to every possible request, so it has to make guesses based on the logic it was given for making those decisions. It cannot know whether the web browser is running on a mobile device, or if the requested document is intended to be sent directly to a printer unless it is told. There are also privacy issues, in that the server-driven method expects the request to send it information about the user making the request.
The second method is known as agent-driven content negotiation. Here, the user makes a request of the server, and the server sends back a list of available alternatives, if any exist. The selection is either made automatically, based on available browser or platform preferences, or manually in the form of options presented in the HTML. The primary drawback to the agent-driven option is the multiple requests to the server for the best possible content. When a proxy server is caching requests to a server that is using agent-driven negotiation, however, it will be able to deliver the appropriate content to any users behind the proxy through a single request to the cache.