content-negotiation.html revision 1e86aafffa12e58c7cfe4244690eff3b82bd02c4
e8058322725ba050014777ee2484f7e833ab1e3aLukas Slebodnik<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozek<!-- Background white, links blue (unvisited), navy (visited), red (active) -->
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozek BGCOLOR="#FFFFFF"
8d00718b943ab8b326320feb50820f0663031817Stephen Gallagher TEXT="#000000"
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozek LINK="#0000FF"
37ea8e70fa13ff9ba563300fb15de0e5e6185d68Lukas Slebodnik VLINK="#000080"
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozek ALINK="#FF0000"
8d00718b943ab8b326320feb50820f0663031817Stephen Gallagher<!--#include virtual="header.html" -->
8d00718b943ab8b326320feb50820f0663031817Stephen Gallagher<H1 ALIGN="CENTER">Content Negotiation</H1>
8d00718b943ab8b326320feb50820f0663031817Stephen GallagherApache's support for content negotiation has been updated to meet the
8d00718b943ab8b326320feb50820f0663031817Stephen GallagherHTTP/1.1 specification. It can choose the best representation of a
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekresource based on the browser-supplied preferences for media type,
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozeklanguages, character set and encoding. It is also implements a
8d00718b943ab8b326320feb50820f0663031817Stephen Gallaghercouple of features to give more intelligent handling of requests from
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekbrowsers which send incomplete negotiation information. <P>
c9f6ca2ca7399c301853ff774c20883fef2b2267Stephen GallagherContent negotiation is provided by the
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozek<A HREF="mod/mod_negotiation.html">mod_negotiation</A> module,
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekwhich is compiled in by default.
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub HrozekA resource may be available in several different representations. For
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekexample, it might be available in different languages or different
37ea8e70fa13ff9ba563300fb15de0e5e6185d68Lukas Slebodnikmedia types, or a combination. One way of selecting the most
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekappropriate choice is to give the user an index page, and let them
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekselect. However it is often possible for the server to choose
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekautomatically. This works because browsers can send as part of each
11496692da75a330de01d5f15b7183d2439efd3cLukas Slebodnikrequest information about what representations they prefer. For
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekexample, a browser could indicate that it would like to see
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekinformation in French, if possible, else English will do. Browsers
c9f6ca2ca7399c301853ff774c20883fef2b2267Stephen Gallagherindicate their preferences by headers in the request. To request only
11496692da75a330de01d5f15b7183d2439efd3cLukas SlebodnikFrench representations, the browser would send
0a0d272844108fe3650a206c39dd4047f10003f2Gowrishankar Rajaiyan Accept-Language: fr
8d00718b943ab8b326320feb50820f0663031817Stephen GallagherNote that this preference will only be applied when there is a choice
764bda08267d867a30ceb07d398dc30be1f4b699Stephen Gallagherof representations and they vary by language.
764bda08267d867a30ceb07d398dc30be1f4b699Stephen GallagherAs an example of a more complex request, this browser has been
764bda08267d867a30ceb07d398dc30be1f4b699Stephen Gallagherconfigured to accept French and English, but prefer French, and to
675f529e1a0ada1b1a400a59465560ab88a6e24cStephen Gallagheraccept various media types, preferring HTML over plain text or other
675f529e1a0ada1b1a400a59465560ab88a6e24cStephen Gallaghertext types, and preferring GIF or JPEG over other media types, but also
675f529e1a0ada1b1a400a59465560ab88a6e24cStephen Gallagherallowing any other media type as a last resort:
764bda08267d867a30ceb07d398dc30be1f4b699Stephen Gallagher Accept-Language: fr; q=1.0, en; q=0.5
764bda08267d867a30ceb07d398dc30be1f4b699Stephen Gallagher Accept: text/html; q=1.0, text/*; q=0.8, image/gif; q=0.6,
675f529e1a0ada1b1a400a59465560ab88a6e24cStephen Gallagher image/jpeg; q=0.6, image/*; q=0.5, */*; q=0.1
11496692da75a330de01d5f15b7183d2439efd3cLukas SlebodnikApache 1.2 supports 'server driven' content negotiation, as defined in
11496692da75a330de01d5f15b7183d2439efd3cLukas Slebodnikthe HTTP/1.1 specification. It fully supports the Accept,
675f529e1a0ada1b1a400a59465560ab88a6e24cStephen GallagherAccept-Language, Accept-Charset and Accept-Encoding request headers.
764bda08267d867a30ceb07d398dc30be1f4b699Stephen GallagherApache 1.3.4 also supports 'transparent' content negotiation, which is
764bda08267d867a30ceb07d398dc30be1f4b699Stephen Gallagheran experimental negotiation protocol defined in RFC 2295 and RFC 2296.
8d00718b943ab8b326320feb50820f0663031817Stephen GallagherIt does not offer support for 'feature negotiation' as defined in
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub HrozekA <STRONG>resource</STRONG> is a conceptual entity identified by a URI
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozek(RFC 2396). An HTTP server like Apache provides access to
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozek<STRONG>representations</STRONG> of the resource(s) within its namespace,
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekwith each representation in the form of a sequence of bytes with a
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekdefined media type, character set, encoding, etc. Each resource may be
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekassociated with zero, one, or more than one representation
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekat any given time. If multiple representations are available,
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekthe resource is referred to as <STRONG>negotiable</STRONG> and each of its
5daa8ae758349c0077fb5f664579809aa0ab4f78Stephen Gallagherrepresentations is termed a <STRONG>variant</STRONG>. The ways in which the
5daa8ae758349c0077fb5f664579809aa0ab4f78Stephen Gallaghervariants for a negotiable resource vary are called the
5daa8ae758349c0077fb5f664579809aa0ab4f78Stephen Gallagher<STRONG>dimensions</STRONG> of negotiation.
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub HrozekIn order to negotiate a resource, the server needs to be given
11496692da75a330de01d5f15b7183d2439efd3cLukas Slebodnikinformation about each of the variants. This is done in one of two
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozek <LI> Using a type map (<EM>i.e.</EM>, a <CODE>*.var</CODE> file) which
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozek names the files containing the variants explicitly, or
11496692da75a330de01d5f15b7183d2439efd3cLukas Slebodnik <LI> Using a 'MultiViews' search, where the server does an implicit
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozek filename pattern match and chooses from among the results.
11496692da75a330de01d5f15b7183d2439efd3cLukas SlebodnikA type map is a document which is associated with the handler
11496692da75a330de01d5f15b7183d2439efd3cLukas Slebodniknamed <CODE>type-map</CODE> (or, for backwards-compatibility with
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekolder Apache configurations, the mime type
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozek<CODE>application/x-type-map</CODE>). Note that to use this feature,
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekyou must have a handler set in the configuration that defines a
5daa8ae758349c0077fb5f664579809aa0ab4f78Stephen Gallagherfile suffix as <CODE>type-map</CODE>; this is best done with a
5daa8ae758349c0077fb5f664579809aa0ab4f78Stephen Gallagher AddHandler type-map .var
5daa8ae758349c0077fb5f664579809aa0ab4f78Stephen Gallagherin the server configuration file. See the comments in the sample config
5daa8ae758349c0077fb5f664579809aa0ab4f78Stephen Gallagherfile for more details. <P>
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub HrozekType map files have an entry for each available variant; these entries
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekconsist of contiguous HTTP-format header lines. Entries for
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekdifferent variants are separated by blank lines. Blank lines are
530ba03ecabb472f17d5d1ab546aec9390492de1Jakub Hrozekillegal within an entry. It is conventional to begin a map file with
URI: foo.en.html
URI: foo.fr.de.html
URI: foo.jpeg
URI: foo.gif
URI: foo.txt
header includes either en or fr (or both) one of foo.en.html
or foo.fr.html will be returned. If the browser does not list
either en or fr as acceptable, foo.html will be returned instead.
<!--#include virtual="footer.html" -->