Content Negotiation

Under Content Negotiation ( content agreement ) refers to a technique in the Hypertext Transfer Protocol, which allows determination of the contents of the requested resource because of the possibilities and advantages of the client.

Operation

In HTTP are content agreement, the request - header fields Accept, Accept-Charset, Accept-Encoding, and Accept-Language available that describe a comma-separated list -priced properties.

The evaluation of the properties is the optional quality parameter q possible values ​​between 0 ( not acceptable ) and 1 ( preferred), allowed; lacking this, the default value of 1 is assumed. At the same value, the specificity of the additional property is used to determine the order depending on the header field, specific to the few preferred specific characteristics.

In addition, the Vary header field should be called those header fields of inquiry in the use of HTTP caching techniques in the response of the web server, which were considered in the vote, thus leading to the unique selection of the transmitted representation of the resource.

If the requested URL is a generic, thus have the representation of the resource is not uniquely describes and instead held a content agreement that shipped representation, however, has its own specific URL, this can be specified in the Content-Location header field.

Example

One of the most common applications is the automatic selection of language (English Language Negotiation ). For this purpose, the client sends its request in the Accept-Language field:

GET / path / to / resource HTTP/1.1 Host: example.com Accept-Language: en-us, en, de, q = 0.5, for q = 0.2 ⋮ This specification is to be interpreted such that the client is German, English and French accepted, although the federal German German high above all other German versions as well as in front of English and French is preferred. If the server thus has a version in German higher German, the Austrian German and Swiss High German, West German version should be delivered.

A response from the Web server could then for example look like this, here German-language content is loaded without specifying a variety of standard German:

HTTP/1.1 200 OK Content-Language: en Content-Location: / en / path / to / resource Vary: Accept-Language ⋮ HTTP status codes

The HTTP provides special status codes that should be sent to the client by the server when a substantive vote has not been possible:

Support of web server

The Apache HTTP Server provides information about the module mod_negotiation the opportunity to offer multiple languages ​​without having to do a lot of complicated configuration. This requires only the ISO 639 identifier of the language will be appended to the file name (the default ), then German browsers that foo.html Request the file actually delivered the foo.html.de file. For this purpose creates mod_negotiation type maps with transparent.

201091
de