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