Content negotiation

What is content negotiation?

Content negotiation is actually part of a feature called dynamic negotiation. The other part of dynamic negotiation is browser negotiation. These two operations are explained below.

Content negotiation is where you provide the server with different file formats for the same resource (variants), and the server will return the most appropriate version to the client.

For example, you may have two versions of an inlined image, a GIF version and a JPEG version. The JPEG version might be of higher quality and smaller, but you need to provide the GIF version to provide a service to clients using older Mosaic style browsers which do not support inline JPEGs.

If you provide both variants to the server and enable content negotiation, then the server will automatically send the GIF image to the older browser and the JPEG image to the browsers that can support it.

Browser negotiation is where you provide two different versions of your HTML files, a plain HTML/2.0 version and a Netscape enhanced version. The server will automatically send the enhanced page to Netscape clients and transparently give older clients the HTML/2.0 versions of your pages.

How do I enable negotiation?

Simply use the administration server to edit the configuration for the virtual server you wish to enable content negotiation for. The option lives in the advanced configuration section called Dynamic negotiation. There are three settings for this option:

Never:No dynamic negotiation is enabled
On variant files:Only negotiate on variant files
Always:Always negotiate

The first option will disable dynamic negotiation completely, the other two determine how you the server finds the variant files for the requested resource.

On variant files

Selecting this option causes the server to only perform negotiation when the requested resource is a variant file, this a file with a mime-type of application/x-type-map, which is mapped to by files with an extension of `.var' by default.

A variant file is a small text file which explicitly states the different variants available for the resource in RFC822 format, along with a preference value. The example is:

URI: url; vary="type"

URI: url.jpg
Content-type: image/jpeg; qs=0.8

URI: url.gif
Content-type: image/gif; qs=0.5

URI: readme.txt
Content-type: text/plain; qs=0.3
This file defines three variants, a jpeg, a gif and a text version. When the client requests this variant file, then the one of the three variants that best matches the client will be returned. For example, if the client can handle all 3 variants, then the jpeg will be returned because it has the highest quality rating (0.8 in this example).

Always

Instead of creating a variant file for every resource you wish to negotiate, there is another simpler method for the server to find the available variants. In this scheme, all of the variants begin with the same name, but have extensions appropriate to their type, eg foo.jpg and foo.gif. Then in the HTML simply refer to the resource as <img src="foo"> (ie. missing off the extension). When the server receives such a request from the client, it will search for all files beginning `foo.' in the same directory, and return the best match to the client. If two variants tie on quality value then the smaller of the two is returned.

Browser negotiation

Simply create your Netscape enhanced documents should have an extension of `.nhtml', and the plain HTML/2.0 documents with an extension of `.html'. Then set dynamic negotiation to `always', and simply refer to your document in the href without the extension.

You will probably want to add an extra entry to the Index Types field also on the advanced configuration page, of the name `index', so that when the client requests a directory, the server will dynamically return either the index.html or index.nhtml file depending on the client. For example, you would alter the default value of the index types field from index.cgi,index,index.html,index.shtml to index.cgi,index,index,index.html,index.shtml


Back to the features index