content-negotiation.xml revision c14037646789087319802aaada2e8534ccab0158
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden<!DOCTYPE manualpage SYSTEM "/style/manualpage.dtd">
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden<!-- $LastChangedRevision$ -->
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden Copyright 2002-2005 The Apache Software Foundation or its licensors, as
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden Licensed under the Apache License, Version 2.0 (the "License");
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden you may not use this file except in compliance with the License.
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden You may obtain a copy of the License at
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden Unless required by applicable law or agreed to in writing, software
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden distributed under the License is distributed on an "AS IS" BASIS,
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott See the License for the specific language governing permissions and
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott limitations under the License.
537857b204a4425e0ea257b0413a02c5c7c5e266Robert Wapshott<manualpage metafile="content-negotiation.xml.meta">
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden <p>Apache supports content negotiation as described in
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott the HTTP/1.1 specification. It can choose the best
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden representation of a resource based on the browser-supplied
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden preferences for media type, languages, character set and
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden encoding. It also implements a couple of features to give
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden more intelligent handling of requests from browsers that send
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna incomplete negotiation information.</p>
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna <p>Content negotiation is provided by the
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna <module>mod_negotiation</module> module, which is compiled in
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna by default.</p>
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna<section id="about"><title>About Content Negotiation</title>
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden <p>A resource may be available in several different
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna representations. For example, it might be available in
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna different languages or different media types, or a combination.
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden One way of selecting the most appropriate choice is to give the
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna user an index page, and let them select. However it is often
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna possible for the server to choose automatically. This works
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden because browsers can send, as part of each request, information
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden about what representations they prefer. For example, a browser
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden could indicate that it would like to see information in French,
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden if possible, else English will do. Browsers indicate their
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna preferences by headers in the request. To request only French
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden representations, the browser would send</p>
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden <p>Note that this preference will only be applied when there is
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden a choice of representations and they vary by language.</p>
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden <p>As an example of a more complex request, this browser has
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden been configured to accept French and English, but prefer
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna French, and to accept various media types, preferring HTML over
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden plain text or other text types, and preferring GIF or JPEG over
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden other media types, but also allowing any other media type as a
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden last resort:</p>
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden Accept-Language: fr; q=1.0, en; q=0.5<br />
c44bbf5d2025d672efe11a37ea6e9c867e78b691Neil Madden Accept: text/html; q=1.0, text/*; q=0.8, image/gif; q=0.6, image/jpeg; q=0.6, image/*; q=0.5, */*; q=0.1
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna <p>Apache supports 'server driven' content negotiation, as
c44bbf5d2025d672efe11a37ea6e9c867e78b691Neil Madden defined in the HTTP/1.1 specification. It fully supports the
c44bbf5d2025d672efe11a37ea6e9c867e78b691Neil Madden <code>Accept</code>, <code>Accept-Language</code>,
c44bbf5d2025d672efe11a37ea6e9c867e78b691Neil Madden <code>Accept-Charset</code> and<code>Accept-Encoding</code>
c44bbf5d2025d672efe11a37ea6e9c867e78b691Neil Madden request headers. Apache also supports 'transparent'
c44bbf5d2025d672efe11a37ea6e9c867e78b691Neil Madden content negotiation, which is an experimental negotiation
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden protocol defined in RFC 2295 and RFC 2296. It does not offer
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna support for 'feature negotiation' as defined in these RFCs.</p>
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden <p>A <strong>resource</strong> is a conceptual entity
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden identified by a URI (RFC 2396). An HTTP server like Apache
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden provides access to <strong>representations</strong> of the
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden resource(s) within its namespace, with each representation in
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden the form of a sequence of bytes with a defined media type,
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden character set, encoding, etc. Each resource may be associated
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden with zero, one, or more than one representation at any given
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden time. If multiple representations are available, the resource
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden is referred to as <strong>negotiable</strong> and each of its
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott representations is termed a <strong>variant</strong>. The ways
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden in which the variants for a negotiable resource vary are called
c44bbf5d2025d672efe11a37ea6e9c867e78b691Neil Madden the <strong>dimensions</strong> of negotiation.</p>
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden<section id="negotiation"><title>Negotiation in Apache</title>
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden <p>In order to negotiate a resource, the server needs to be
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna given information about each of the variants. This is done in
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden one of two ways:</p>
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna <li>Using a type map (<em>i.e.</em>, a <code>*.var</code>
ae6eb91d10bf796c4affdfdb6f838386cc70aaf3David Luna file) which names the files containing the variants
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden explicitly, or</li>
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden <li>Using a 'MultiViews' search, where the server does an
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden implicit filename pattern match and chooses from among the
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden results.</li>
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott <section id="type-map"><title>Using a type-map file</title>
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden <p>A type map is a document which is associated with the handler
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden named <code>type-map</code> (or, for backwards-compatibility with
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden older Apache configurations, the <glossary>MIME-type</glossary>
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden <code>application/x-type-map</code>). Note that to use this
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden feature, you must have a handler set in the configuration that
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden defines a file suffix as <code>type-map</code>; this is best done
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden <p>Type map files should have the same name as the resource
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden which they are describing, and have an entry for each available
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden variant; these entries consist of contiguous HTTP-format header
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott lines. Entries for different variants are separated by blank
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott lines. Blank lines are illegal within an entry. It is
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott conventional to begin a map file with an entry for the combined
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott entity as a whole (although this is not required, and if
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott present will be ignored). An example map file is shown below.
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott This file would be named <code>foo.var</code>, as it describes
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott URI: foo<br />
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott Content-language: en<br />
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott Content-type: text/html;charset=iso-8859-2<br />
f56a278c148b90f6c2a675e0c1fa8686ca5abed4Robert Wapshott Content-language: fr, de<br />
d45a839aef1439938b43cec508f1bbbd3c5c235eNeil Madden <p>Note also that a typemap file will take precedence over the
href="mod/mod_negotiation.html#typemaps">mod_negotation
href="http://ppewww.ph.gla.ac.uk/~flavell/www/lang-neg.html">Language