]> granicus.if.org Git - apache/blob - docs/manual/mod/mod_mime_magic.xml
New xml versions.
[apache] / docs / manual / mod / mod_mime_magic.xml
1 <?xml version="1.0"?>
2 <!DOCTYPE modulesynopsis SYSTEM "../style/modulesynopsis.dtd">
3 <?xml-stylesheet type="text/xsl" href="../style/manual.xsl"?>
4 <modulesynopsis>
5
6 <name>mod_mime_magic</name>
7 <description>Determines the MIME type of a file
8     by looking at a few bytes of its contents</description>
9 <status>Extension</status>
10 <sourcefile>mod_mime_magic.c</sourcefile>
11 <identifier>mime_magic_module</identifier>
12
13 <summary>
14     <p>This module determines the MIME type of files in the same
15     way the Unix file(1) command works: it looks at the first few
16     bytes of the file. It is intended as a "second line of defense"
17     for cases that <module>mod_mime</module> can't
18     resolve. To assure that mod_mime gets first try at determining
19     a file's MIME type, be sure to list mod_mime_magic
20     <strong>before</strong> mod_mime in the configuration.</p>
21
22     <p>This module is derived from a free version of the
23     <code>file(1)</code> command for Unix, which uses "magic
24     numbers" and other hints from a file's contents to figure out
25     what the contents are. This module is active only if the magic
26     file is specified by the <directive module="mod_mime_magic"
27     >MimeMagicFile</directive> directive.</p>
28 </summary>
29
30 <section><title>Format of the Magic File</title>
31
32     <p>The contents of the file are plain ASCII text in 4-5
33     columns. Blank lines are allowed but ignored. Commented lines
34     use a hash mark "#". The remaining lines are parsed for the
35     following columns:</p>
36
37     <table border="1">
38       <tr valign="top">
39         <th>Column</th>
40
41         <th>Description</th>
42       </tr>
43
44       <tr valign="top">
45         <td>1</td>
46
47         <td>byte number to begin checking from<br />
48          "&gt;" indicates a dependency upon the previous non-"&gt;"
49         line</td>
50       </tr>
51
52       <tr valign="top">
53         <td>2</td>
54
55         <td>
56           type of data to match 
57
58           <table border="1">
59             <tr>
60               <td>byte</td>
61
62               <td>single character</td>
63             </tr>
64
65             <tr>
66               <td>short</td>
67
68               <td>machine-order 16-bit integer</td>
69             </tr>
70
71             <tr>
72               <td>long</td>
73
74               <td>machine-order 32-bit integer</td>
75             </tr>
76
77             <tr>
78               <td>string</td>
79
80               <td>arbitrary-length string</td>
81             </tr>
82
83             <tr>
84               <td>date</td>
85
86               <td>long integer date (seconds since Unix
87               epoch/1970)</td>
88             </tr>
89
90             <tr>
91               <td>beshort</td>
92
93               <td>big-endian 16-bit integer</td>
94             </tr>
95
96             <tr>
97               <td>belong</td>
98
99               <td>big-endian 32-bit integer</td>
100             </tr>
101
102             <tr>
103               <td>bedate</td>
104
105               <td>big-endian 32-bit integer date</td>
106             </tr>
107
108             <tr>
109               <td>leshort</td>
110
111               <td>little-endian 16-bit integer</td>
112             </tr>
113
114             <tr>
115               <td>lelong</td>
116
117               <td>little-endian 32-bit integer</td>
118             </tr>
119
120             <tr>
121               <td>ledate</td>
122
123               <td>little-endian 32-bit integer date</td>
124             </tr>
125           </table>
126         </td>
127       </tr>
128
129       <tr valign="top">
130         <td>3</td>
131
132         <td>contents of data to match</td>
133       </tr>
134
135       <tr valign="top">
136         <td>4</td>
137
138         <td>MIME type if matched</td>
139       </tr>
140
141       <tr valign="top">
142         <td>5</td>
143
144         <td>MIME encoding if matched (optional)</td>
145       </tr>
146     </table>
147
148     <p>For example, the following magic file lines would recognize
149     some audio formats.</p>
150 <example>
151 <pre>
152 # Sun/NeXT audio data
153 0       string          .snd
154 &gt;12     belong          1               audio/basic
155 &gt;12     belong          2               audio/basic
156 &gt;12     belong          3               audio/basic
157 &gt;12     belong          4               audio/basic
158 &gt;12     belong          5               audio/basic
159 &gt;12     belong          6               audio/basic
160 &gt;12     belong          7               audio/basic
161 &gt;12     belong          23              audio/x-adpcm
162 </pre>
163 </example>
164     <p>Or these would recognize the difference between "*.doc" files
165     containing Microsoft Word or FrameMaker documents. (These are
166     incompatible file formats which use the same file suffix.)</p>
167 <example>
168 <pre>
169 # Frame
170 0       string          \&lt;MakerFile     application/x-frame
171 0       string          \&lt;MIFFile       application/x-frame
172 0       string          \&lt;MakerDictionary       application/x-frame
173 0       string          \&lt;MakerScreenFon        application/x-frame
174 0       string          \&lt;MML           application/x-frame
175 0       string          \&lt;Book          application/x-frame
176 0       string          \&lt;Maker         application/x-frame
177
178 # MS-Word
179 0       string          \376\067\0\043                  application/msword
180 0       string          \320\317\021\340\241\261        application/msword
181 0       string          \333\245-\0\0\0                 application/msword
182 </pre>
183 </example>
184     <p>An optional MIME encoding can be included as a fifth column.
185     For example, this can recognize gzipped files and set the
186     encoding for them.</p>
187 <example>
188 <pre>
189 # gzip (GNU zip, not to be confused with [Info-ZIP/PKWARE] zip archiver)
190 0       string          \037\213        application/octet-stream        x-gzip
191 </pre>
192 </example>
193 </section>
194
195 <section><title>Performance Issues</title>
196     <p>This module is not for every system. If your system is barely
197     keeping up with its load or if you're performing a web server
198     benchmark, you may not want to enable this because the
199     processing is not free.</p>
200
201     <p>However, an effort was made to improve the performance of
202     the original file(1) code to make it fit in a busy web server.
203     It was designed for a server where there are thousands of users
204     who publish their own documents. This is probably very common
205     on intranets. Many times, it's helpful if the server can make
206     more intelligent decisions about a file's contents than the
207     file name allows ...even if just to reduce the "why doesn't my
208     page work" calls when users improperly name their own files.
209     You have to decide if the extra work suits your
210     environment.</p>
211
212     <p>When compiling an Apache server, this module should be at or
213     near the top of the list of modules in the Configuration file.
214     The modules are listed in increasing priority so that will mean
215     this one is used only as a last resort, just like it was
216     designed to.</p>
217
218 </section>
219
220 <section id="notes"><title>Notes</title>
221
222     <p>The following notes apply to the mod_mime_magic module and are
223     included here for compliance with contributors' copyright
224     restrictions that require their acknowledgment. </p>
225 <pre>
226 /*
227  * mod_mime_magic: MIME type lookup via file magic numbers
228  * Copyright (c) 1996-1997 Cisco Systems, Inc.
229  *
230  * This software was submitted by Cisco Systems to the Apache Group in July
231  * 1997.  Future revisions and derivatives of this source code must
232  * acknowledge Cisco Systems as the original contributor of this module.
233  * All other licensing and usage conditions are those of the Apache Group.
234  *
235  * Some of this code is derived from the free version of the file command
236  * originally posted to comp.sources.unix.  Copyright info for that program
237  * is included below as required.
238  * ---------------------------------------------------------------------------
239  * - Copyright (c) Ian F. Darwin, 1987. Written by Ian F. Darwin.
240  *
241  * This software is not subject to any license of the American Telephone and
242  * Telegraph Company or of the Regents of the University of California.
243  *
244  * Permission is granted to anyone to use this software for any purpose on any
245  * computer system, and to alter it and redistribute it freely, subject to
246  * the following restrictions:
247  *
248  * 1. The author is not responsible for the consequences of use of this
249  * software, no matter how awful, even if they arise from flaws in it.
250  *
251  * 2. The origin of this software must not be misrepresented, either by
252  * explicit claim or by omission.  Since few users ever read sources, credits
253  * must appear in the documentation.
254  *
255  * 3. Altered versions must be plainly marked as such, and must not be
256  * misrepresented as being the original software.  Since few users ever read
257  * sources, credits must appear in the documentation.
258  *
259  * 4. This notice may not be removed or altered.
260  * -------------------------------------------------------------------------
261  *
262  * For compliance with Mr Darwin's terms: this has been very significantly
263  * modified from the free "file" command.
264  * - all-in-one file for compilation convenience when moving from one
265  *   version of Apache to the next.
266  * - Memory allocation is done through the Apache API's pool structure.
267  * - All functions have had necessary Apache API request or server
268  *   structures passed to them where necessary to call other Apache API
269  *   routines.  (<em>i.e.</em>, usually for logging, files, or memory allocation in
270  *   itself or a called function.)
271  * - struct magic has been converted from an array to a single-ended linked
272  *   list because it only grows one record at a time, it's only accessed
273  *   sequentially, and the Apache API has no equivalent of realloc().
274  * - Functions have been changed to get their parameters from the server
275  *   configuration instead of globals.  (It should be reentrant now but has
276  *   not been tested in a threaded environment.)
277  * - Places where it used to print results to stdout now saves them in a
278  *   list where they're used to set the MIME type in the Apache request
279  *   record.
280  * - Command-line flags have been removed since they will never be used here.
281  *
282  */
283 </pre>
284 </section>
285
286 <directivesynopsis>
287 <name>MimeMagicFile</name>
288 <description>Enable MIME-type determination based on file contents
289 using the specified magic file</description>
290 <syntax>MimeMagicFile <em>file-path</em></syntax>
291 <contextlist><context>server config</context>
292 <context>virtual host</context></contextlist>
293
294 <usage>
295     <p>The <directive>MimeMagicFile</directive> directive can be used to
296     enable this module, the default file is distributed at
297     <code>conf/magic</code>. Non-rooted paths are relative to the
298     ServerRoot. Virtual hosts will use the same file as the main
299     server unless a more specific setting is used, in which case
300     the more specific setting overrides the main server's file.</p>
301 </usage>
302 </directivesynopsis>
303 </modulesynopsis>
304