]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_negotiation.xml
document the changed behaviour of mod_negotiation.
[apache] / docs / manual / mod / mod_negotiation.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.en.xsl"?>
4 <modulesynopsis>
5
6 <name>mod_negotiation</name>
7 <description>Provides for <a
8     href="../content-negotiation.html">content negotiation</a></description>
9 <status>Base</status>
10 <sourcefile>mod_negotiation.c</sourcefile>
11 <identifier>negotiation_module</identifier>
12
13 <summary>
14     <p>Content negotiation, or more accurately content selection, is
15     the selection of the document that best matches the clients
16     capabilities, from one of several available documents. There
17     are two implementations of this.</p>
18
19     <ul>
20       <li>A type map (a file with the handler
21       <code>type-map</code>) which explicitly lists the files
22       containing the variants.</li>
23
24       <li>A MultiViews search (enabled by the <code>MultiViews</code>
25       <directive module="core">Options</directive>), where the server does
26       an implicit filename pattern match, and choose from amongst the
27       results.</li>
28     </ul>
29 </summary>
30 <seealso><directive module="core">Options</directive></seealso>
31 <seealso><module>mod_mime</module></seealso>
32 <seealso><a href="../content-negotiation.html">Content
33 Negotiation</a></seealso>
34 <seealso><a href="../env.html">Environment Variables</a></seealso>
35
36 <section id="typemaps"><title>Type maps</title>
37     <p>A type map has a format similar to RFC822 mail headers. It
38     contains document descriptions separated by blank lines, with
39     lines beginning with a hash character ('#') treated as
40     comments. A document description consists of several header
41     records; records may be continued on multiple lines if the
42     continuation lines start with spaces. The leading space will be
43     deleted and the lines concatenated. A header record consists of
44     a keyword name, which always ends in a colon, followed by a
45     value. Whitespace is allowed between the header name and value,
46     and between the tokens of value. The headers allowed are: </p>
47
48     <dl>
49       <dt><code>Content-Encoding:</code></dt>
50       <dd>The encoding of the file. Apache only recognizes
51       encodings that are defined by an <directive
52       module="mod_mime">AddEncoding</directive> directive.
53       This normally includes the encodings <code>x-compress</code>
54       for compress'd files, and <code>x-gzip</code> for gzip'd
55       files. The <code>x-</code> prefix is ignored for encoding
56       comparisons.</dd>
57
58       <dt><code>Content-Language:</code></dt>
59       <dd>The language(s) of the variant, as an Internet standard
60       language tag (<a href="http://www.ietf.org/rfc/rfc1766.txt"
61       >RFC 1766</a>). An example is <code>en</code>,
62       meaning English. If the variant contains more than one
63       language, they are separated by a comma.</dd>
64
65       <dt><code>Content-Length:</code></dt>
66       <dd>The length of the file, in bytes. If this header is not
67       present, then the actual length of the file is used.</dd>
68
69       <dt><code>Content-Type:</code></dt>
70
71       <dd>
72         The MIME media type of the document, with optional
73         parameters. Parameters are separated from the media type
74         and from one another by a semi-colon, with a syntax of
75         <code>name=value</code>. Common parameters include: 
76
77         <dl>
78           <dt><code>level</code></dt>
79           <dd>an integer specifying the version of the media type.
80           For <code>text/html</code> this defaults to 2, otherwise
81           0.</dd>
82
83           <dt><code>qs</code></dt>
84           <dd>a floating-point number with a value in the range 0.0
85           to 1.0, indicating the relative 'quality' of this variant
86           compared to the other available variants, independent of
87           the client's capabilities. For example, a jpeg file is
88           usually of higher source quality than an ascii file if it
89           is attempting to represent a photograph. However, if the
90           resource being represented is ascii art, then an ascii
91           file would have a higher source quality than a jpeg file.
92           All <code>qs</code> values are therefore specific to a given
93           resource.</dd>
94         </dl>
95
96         <example><title>Example</title>
97           Content-Type: image/jpeg; qs=0.8
98         </example>
99       </dd>
100
101       <dt><code>URI:</code></dt>
102       <dd>uri of the file containing the variant (of the given
103       media type, encoded with the given content encoding). These
104       are interpreted as URLs relative to the map file; they must
105       be on the same server (!), and they must refer to files to
106       which the client would be granted access if they were to be
107       requested directly.</dd>
108
109       <dt><code>Body:</code></dt>
110       <dd>New in Apache 2.0, the actual content of the resource may
111       be included in the type-map file using the Body header.  This
112       header must contain a string that designates a delimiter for
113       the body content. Then all following lines in the type map
114       file will be considered part of the resource body until the
115       delimiter string is found.
116
117       <example><title>Example:</title>
118         Body:----xyz----<br />
119         &lt;html&gt;<br />
120         &lt;body&gt;<br />
121         &lt;p&gt;Content of the page.&lt;/p&gt;<br />
122         &lt;/body&gt;<br />
123         &lt;/html&gt;<br />
124         ----xyz----
125       </example>
126       </dd>
127     </dl>
128 </section>
129
130 <section id="multiviews"><title>MultiViews</title>
131     <p>A MultiViews search is enabled by the <code>MultiViews</code>
132     <directive module="core">Options</directive>. If the server receives a
133     request for <code>/some/dir/foo</code> and
134     <code>/some/dir/foo</code> does <em>not</em> exist, then the
135     server reads the directory looking for all files named
136     <code>foo.*</code>, and effectively fakes up a type map which
137     names all those files, assigning them the same media types and
138     content-encodings it would have if the client had asked for one
139     of them by name. It then chooses the best match to the client's
140     requirements, and returns that document.</p>
141 </section>
142
143 <directivesynopsis>
144 <name>CacheNegotiatedDocs</name>
145 <description>Allows content-negotiated documents to be 
146 cached by proxy servers</description>
147 <syntax>CacheNegotiatedDocs On|Off</syntax>
148 <default>CacheNegotiatedDocs Off</default>
149 <contextlist><context>server config</context><context>virtual host</context>
150 </contextlist>
151 <compatibility>The syntax changed in version 2.0.</compatibility>
152
153 <usage>
154     <p>If set, this directive allows content-negotiated documents
155     to be cached by proxy servers. This could mean that clients
156     behind those proxys could retrieve versions of the documents
157     that are not the best match for their abilities, but it will
158     make caching more efficient.</p>
159
160     <p>This directive only applies to requests which come from
161     HTTP/1.0 browsers. HTTP/1.1 provides much better control over
162     the caching of negotiated documents, and this directive has no
163     effect in responses to HTTP/1.1 requests.</p>
164
165     <p>Prior to version 2.0,
166     <directive>CacheNegotiatedDocs</directive> did not take an
167     argument; it was turned on by the presence of the directive by
168     itself.</p>
169 </usage>
170 </directivesynopsis>
171
172 <directivesynopsis>
173 <name>ForceLanguagePriority</name>
174 <description>Action to take if a single acceptable document is not 
175 found</description>
176 <syntax>ForceLanguagePriority None|Prefer|Fallback [Prefer|Fallback]</syntax>
177 <default>ForceLanguagePriority Prefer</default>
178 <contextlist><context>server config</context><context>virtual host</context>
179 <context>directory</context><context>.htaccess</context></contextlist>
180 <override>FileInfo</override>
181 <compatibility>Available in version 2.0.30 and later</compatibility>
182
183 <usage>
184     <p>The <directive>ForceLanguagePriority</directive> directive uses
185     the given <directive
186     module="mod_negotiation">LanguagePriority</directive> to satisfy
187     negotation where the server could otherwise not return a single
188     matching document.</p>
189
190     <p><code>ForceLanguagePriority Prefer</code> uses
191     <code>LanguagePriority</code> to serve a one valid result, rather
192     than returning an HTTP result 300 (MULTIPLE CHOICES) when there
193     are several equally valid choices.  If the directives below were
194     given, and the user's <code>Accept-Language</code> header assigned
195     <code>en</code> and <code>de</code> each as quality <code>.500</code>
196     (equally acceptable) then the first matching variant, <code>en</code>,
197     will be served.</p>
198
199     <example>
200       LanguagePriority en fr de<br />
201       ForceLanguagePriority Prefer
202     </example>
203
204     <p><code>ForceLanguagePriority Fallback</code> uses
205     <directive module="mod_negotiation">LanguagePriority</directive> to
206     serve a valid result, rather than returning an HTTP result 406
207     (NOT ACCEPTABLE). If the directives below were given, and the user's
208     <code>Accept-Language</code> only permitted an <code>es</code>
209     language response, but such a variant isn't found, then the first
210     variant from the <directive module="mod_negotiation"
211     >LanguagePriority</directive> list below will be served.</p>
212
213     <example>
214       LanguagePriority en fr de<br />
215       ForceLanguagePriority Fallback
216     </example>
217
218     <p>Both options, <code>Prefer</code> and <code>Fallback</code>, may be
219     specified, so either the first matching variant from <directive
220     module="mod_negotiation">LanguagePriority</directive> will be served if
221     more than one variant is acceptable, or first available document will
222     be served if none of the variants matched the client's acceptable list
223     of languages.</p>
224 </usage>
225 <seealso><directive module="mod_mime">AddLanguage</directive></seealso>
226 </directivesynopsis>
227
228 <directivesynopsis>
229 <name>LanguagePriority</name>
230 <description>The precendence of language variants for cases where
231 the client does not express a preference</description>
232 <syntax>LanguagePriority <var>MIME-lang</var> [<var>MIME-lang</var>]
233 ...</syntax>
234 <contextlist><context>server config</context><context>virtual host</context>
235 <context>directory</context><context>.htaccess</context></contextlist>
236 <override>FileInfo</override>
237
238 <usage>
239     <p>The <directive>LanguagePriority</directive> sets the precedence
240     of language variants for the case where the client does not
241     express a preference, when handling a MultiViews request. The list
242     of <var>MIME-lang</var> are in order of decreasing preference.</p>
243
244     <example><title>Example:</title>
245       LanguagePriority en fr de
246     </example>
247
248     <p>For a request for <code>foo.html</code>, where
249     <code>foo.html.fr</code> and <code>foo.html.de</code> both
250     existed, but the browser did not express a language preference,
251     then <code>foo.html.fr</code> would be returned.</p>
252
253     <p>Note that this directive only has an effect if a 'best'
254     language cannot be determined by any other means or the <directive
255     module="mod_negotiation">ForceLanguagePriority</directive> directive
256     is not <code>None</code>. Correctly implemented HTTP/1.1 requests
257     will mean this directive has no effect.</p>
258 </usage>
259 <seealso><directive module="mod_mime">AddLanguage</directive></seealso>
260 </directivesynopsis>
261
262 </modulesynopsis>