Content negotiation
Under Content Negotiation ( content agreement ) refers to a technique in Hypertext Transfer Protocol that a vote of the contents of the requested resource because of the opportunities and benefits of the client allows.
functionality
In HTTP, the request header fields Accept , Accept-Charset , Accept-Encoding and Accept-Language are available for agreeing the content , which describe a list of evaluated properties separated by commas.
- Accept
- List of accepted content types . The counterpart in the answer is the Content-Type field
- Accept charset
- List of accepted character sets or character encodings . The counterpart in the answer is the charset parameter of the Content-Type field
- Accept-Encoding
- List of accepted encodings. The counterpart in the answer is the content-encoding field
- Accept-Language
- List of accepted languages. The counterpart in the answer is the content language field
The evaluation of the properties is possible via the optional quality q
parameter, which allows values between 0 (unacceptable) and 1 (preferred); if this is missing, the default value 1 is assumed. If the value is the same, depending on the header field, the specificity of the property is also used when determining the sequence, with more specific properties being preferred to less specific properties.
In addition, when using HTTP caching techniques, the Vary header field in the response from the web server should include those header fields of the request that were taken into account during the vote, i.e. that led to the unambiguous selection of the sent representation of the resource.
If the requested URL is generic, i.e. it does not clearly describe the representation of the resource and instead a content agreement takes place, but the delivered representation has its own specific URL, this can be specified in the content location header field.
example
One of the most widespread applications is automatic language selection ( Language Negotiation ). To do this, the client sends the Accept-Language field in its request :
GET /path/to/resource HTTP/1.1 Host: example.com Accept-Language: de-de, de, en;q=0.5, fr;q=0.2 ⋮
This information is to be interpreted in such a way that the client accepts German, English and French, whereby West German Standard German is preferred over all other German variants as well as English and French. So if the server has a version in German High German, Austrian German and Swiss High German , the German version should be delivered.
A response from the web server could then look like the following, for example, German-language content is loaded here without specifying a variety of standard German :
HTTP/1.1 200 OK Content-Language: de Content-Location: /de/path/to/resource Vary: Accept-Language ⋮
HTTP status codes
The HTTP offers special status codes that the server should send to the client if it was not possible to coordinate the content:
- 300 multiple choices
- Is sent if several resources matching the conditions in the request can be found elsewhere or if the server wants to leave the selection to the client. The appropriate addresses and characteristics of the choices should be given in the document; the server can send the address of a preferred document in the Location header field.
- 406 Not Acceptable
- Is sent if the requested resource exists, but the conditions sent by the client cannot be met.
- 506 Variant Also Negotiates
- The content agreement of the request results in a circular reference .
Web server support
The Apache HTTP Server offers mod_negotiation
the possibility to offer several languages via the module without having to operate a complex configuration. For this purpose (in the standard setting ) only the ISO-639 identifier of the respective language has to be appended to the file name, so German browsers that foo.html
request the file actually receive the file foo.html.de
. For this purpose, mod_negotiation
transparent creates typemaps.
Web links
-
RFC 2616 HTTP 1.1 specification
- Description of the header fields Accept , Accept-Charset , Accept-Encoding and Accept-Language (English)
- Section on content negotiation (English)
- RFC 2295 Transparent Content Negotiation in HTTP (English)
- Apache Content Negotiation (English)
- W3C I18n FAQ: When is it appropriate to use language negotiation
Individual evidence
- ↑ Ben Laurie, Peter Laurie: Apache. The comprehensive manual. 2nd Edition. German edition of the 3rd edition. O'Reilly, Beijing et al. 2003, ISBN 3-89721-356-7 .
- ↑ RFC 2295 .
- ↑ https://httpd.apache.org/docs/current/mod/mod_negotiation.html