My opinion about negotiated content in server programming
2 Comments
Written by Robert on April 7, 2008 – 8:59 am
The HTTP/1.1 protocol supports sophisticated mechanisms for clients to specify the desired form of content. In fact, the mechanisms are too sophisticated for most web browsers; only a subset of the content negotiation features gets used regularly.
A client can express preferences using headers like Accept, Accept-Language and Accept-Charset; these should utilize data entered through the browser’s preferences dialogs (e.g. IE: Tools/Internet/Languages etc; Netscape: Edit/Preferences/Navigator/Languages). (There is also an Accept-Encoding header that is used more or less automatically by the browser to indicate whether it can deal with gzip compressed encoded data or other forms of data encoding). The following examples of Accept headers are taken from the HTTP/1.1 specification; they indicate something of the scope for this control mechanism.
The first example might occur in a request for an audio resource; it specifies that the preferred form would be a resource in audio/basic format (with default ‘quality’ index 1.0), but any other form would be acceptable (though it would only merit one fifth of the approval of the basic format). The second request might be from a request for a text resource; this client would be happy with either HTML or x-c format data; if these are not available a dvi file would be accepted, and if not that then plain text is OK.
The format of these Accept requests has a data type and sub-type (with ‘*’meaning any subtype), and an optional ‘quality’ rating. Currently, most browsers do not have mechanisms for entering these quality ratings etc. It would also be unusual for a resource to be available in a large number of formats.
Language and character set controls are more commonly used and are a little better supported in current browsers. An Accept-Charset header can specify acceptable character sets; the server might have a document presented in different ways using various character sets to their best effect.
The Accept-Language header is the most frequently used; it allows a client to specify language preferences. Again, using an example from the HTTP/1.1 reference, one could have:
Accept-Language: da, en-gb;q=0.8, en;q=0.7
Such a header in a request would indicate a preference for a Danish version of the document, with a second preference being English (with British English slightly preferred over other dialects). Obviously, the server must have multiple copies of resources if it is to honor such requests. There are various possible approaches that can be used by the server to recognize the version of the document most suited to the client. One approach uses language codes as extra file extensions. Thus, you might find a directory with the files index.html.de (German), index.html.fr (French) and index.html.en (English).
Popularity: 41% [?]

2 Trackback(s)