mod_mime_magic.html revision cbdec3d6cc7bc0c1a344fb19bf00d1af1ca2365a
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <!-- Background white, links blue (unvisited), navy (visited), red (active) -->
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc BGCOLOR="#FFFFFF"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd TEXT="#000000"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd LINK="#0000FF"
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen VLINK="#000080"
2e545ce2450a9953665f701bb05350f0d3f26275nd ALINK="#FF0000"
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd This module is an optional extension to the Apache HTTPD server.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd The current version can be obtained from
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen <a href="http://www.employees.org/~ikluft/apache/mod_mime_magic/">
3f08db06526d6901aa08c110b5bc7dde6bc39905nd http://www.employees.org/~ikluft/apache/mod_mime_magic/</a>.
3f08db06526d6901aa08c110b5bc7dde6bc39905nd This module is derived from a free version of the <code>file(1)</code>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd command for Unix,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd which uses "magic numbers" and other hints from a file's contents to
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd figure out what the contents are.
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd In the case of this module,
ecc5150d35c0dc5ee5119c2717e6660fa331abbftakashi it tries to figure out the MIME type of the file.
ad74a0524a06bfe11b7de9e3b4ce7233ab3bd3f7nd This module is only active if the magic file exists and
63f06dce77bb2d9b1c5aa5deeb47a1069987fd1end was successfully opened at server-configuration time.
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen The magic file can be named by the
d474d8ef01ec5c2a09341cd148851ed383c3287crbowen <A HREF="#mimemagicfile"><code>MimeMagicFile</code></a>
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem The contents of the file are plain ASCII text in 4-5 columns.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd Blank lines are allowed but ignored.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd Commented lines use a hash mark "#".
3f08db06526d6901aa08c110b5bc7dde6bc39905nd The remaining lines are parsed for the following columns:
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <td>byte number to begin checking from
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd ">" indicates a dependency upon the previous non-">" line</td>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <td>type of data to match
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <tr><td>short</td><td>machine-order 16-bit integer</td></tr>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <tr><td>long</td><td>machine-order 32-bit integer</td></tr>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <tr><td>beshort</td><td>big-endian 16-bit integer</td></tr>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <tr><td>belong</td><td>big-endian 32-bit integer</td></tr>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <tr><td>bedate</td><td>big-endian 32-bit integer date</td></tr>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <tr><td>leshort</td><td>little-endian 16-bit integer</td></tr>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <tr><td>lelong</td><td>little-endian 32-bit integer</td></tr>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <tr><td>ledate</td><td>little-endian 32-bit integer date</td></tr>
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd For example, the following magic file lines
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd would recognize some audio formats.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd0 string .snd
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd Or these would recognize the difference between "*.doc" files containing
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd Microsoft Word or FrameMaker documents. (These are incompatible file
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd formats which use the same file suffix.)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd An optional MIME encoding can be included as a fifth column.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd For example, this can recognize gzipped files and set the encoding
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd# gzip (GNU zip, not to be confused with [Info-ZIP/PKWARE] zip archiver)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd This module is not for every system. If your system is barely keeping
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd up with its load or if you're performing a web server benchmark,
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd you may not want to enable this because the processing is not free.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd However, an effort was made to improve the performance of the original
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd file(1) code to make it fit in a busy web server.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd It was designed for a server where there are thousands of users who
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd publish their own documents.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd This is probably very common on intranets.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd Many times, it's helpful
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd if the server can make more intelligent decisions about a file's
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd contents than the file name allows
71fccc298df6a1540d408151a26aa22beed55d0bnd ...even if just to reduce the "why doesn't my page work" calls
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd when users improperly name their own files.
a8703cfb67133446eef7af1043640e71486e9ecand You have to decide if the extra work suits your environment.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd When compiling an Apache server, this module should be at or near the
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd top of the list of modules in the Configuration file. The modules are
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd listed in increasing priority so that will mean this one is used only
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd as a last resort, just like it was designed to.
71fccc298df6a1540d408151a26aa22beed55d0bnd MimeMagicFile
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd <STRONG>Syntax:</STRONG> MimeMagicFile <em>magic-file-name</em>
316f02e3836836c82e19019ff23f90a7ebc65289nilgun <STRONG>Context:</STRONG> server config, virtual host
4b311579b2c8aebac85fb7cb8ac89e6c37b4bc1asf The MimeMagicFile directive can be used to change the location of the
50c04f297d76a57ead2fa6b73845f7563b1fc788sf magic file from its default location at <code>conf/magic</code>.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd Non-rooted paths are relative to the ServerRoot.
909ce17e2bd0faef7b1c294f2307f009793fd493nd Patches and suggestions for mod_mime_magic should be sent to
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd Ian Kluft <ikluft<!--- comment inserted to discourage spam --->@cisco.com>.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd Note that enhancements are done on a volunteer basis so no timetable can
cd34a6fbf0a2619544a72eadb73f309370bf6682wrowe be committed for any particular request.
65a611af7093423efb91e5794b8887a527d4cf63trawick Obviously, patches are given much higher priority over plain requests.
ffb88a4885747797937e30a5ac8b1606da3cb4adnd The following notes apply to the mod_mime_magic module and are
6fe26506780e73be2a412d758af77fafdf03291and included here for compliance with contributors' copyright restrictions
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd that require their acknowledgement.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * mod_mime_magic: MIME type lookup via file magic numbers
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Copyright (c) 1996-1997 Cisco Systems, Inc.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * This software was submitted by Cisco Systems to the Apache Group in July
78f97ce162b66a0dbfd7af4dcd9984f162569b04minfrin * 1997. Future revisions and derivatives of this source code must
f5a398cc8880978754903f9ece8e4beb63a81cedrbowen * acknowledge Cisco Systems as the original contributor of this module.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * All other licensing and usage conditions are those of the Apache Group.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Some of this code is derived from the free version of the file command
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * originally posted to comp.sources.unix. Copyright info for that program
7906201913b68fe78b9d6a22ab33bf21d82c490eminfrin * is included below as required.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * ---------------------------------------------------------------------------
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * - Copyright (c) Ian F. Darwin, 1987. Written by Ian F. Darwin.
e8b603fa9ccf7b17b11b42df6d8916fd97c2331dnd * This software is not subject to any license of the American Telephone and
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Telegraph Company or of the Regents of the University of California.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * Permission is granted to anyone to use this software for any purpose on any
611049e38bfbaeb173d2d7fab2e44a48753436a1nd * computer system, and to alter it and redistribute it freely, subject to
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * the following restrictions:
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * 1. The author is not responsible for the consequences of use of this
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * software, no matter how awful, even if they arise from flaws in it.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * 2. The origin of this software must not be misrepresented, either by
03a4ff9ac4c9b8009249010e7c53bb86ff05915and * explicit claim or by omission. Since few users ever read sources, credits
5effc8b39fae5cd169d17f342bfc265705840014rbowen * must appear in the documentation.
d0828c8a321dc5e9ea60550f052294669c08cf93jim * 3. Altered versions must be plainly marked as such, and must not be
d0828c8a321dc5e9ea60550f052294669c08cf93jim * misrepresented as being the original software. Since few users ever read
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * sources, credits must appear in the documentation.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * 4. This notice may not be removed or altered.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * -------------------------------------------------------------------------
6c4ef4a72d9897e53365b94103f4bd819fd0d3acnd * For complicance with Mr Darwin's terms: this has been very significantly
2704de98885368683621b01c8f8f4e4b01557611takashi * modified from the free "file" command.
2704de98885368683621b01c8f8f4e4b01557611takashi * - all-in-one file for compilation convenience when moving from one
2704de98885368683621b01c8f8f4e4b01557611takashi * version of Apache to the next.
d0828c8a321dc5e9ea60550f052294669c08cf93jim * - Memory allocation is done through the Apache API's pool structure.
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * - All functions have had necessary Apache API request or server
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * structures passed to them where necessary to call other Apache API
c819c19c2f1ffbf3a3f12a4070cc6c3f4ea2a6f2sf * routines. (i.e. usually for logging, files, or memory allocation in
d2b809e5d72658bff23819d8b77f20e4939af541nd * itself or a called function.)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * - struct magic has been converted from an array to a single-ended linked
a4687128d43515b5791a6efc6ba55314478f9552jim * list because it only grows one record at a time, it's only accessed
04bab87733a0e93a926e82311c85cd8ac06a032fnd * sequentially, and the Apache API has no equivalent of realloc().
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * - Functions have been changed to get their parameters from the server
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * configuration instead of globals. (It should be reentrant now but has
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * not been tested in a threaded environment.)
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * - Places where it used to print results to stdout now saves them in a
5effc8b39fae5cd169d17f342bfc265705840014rbowen * list where they're used to set the MIME type in the Apache request
6116c12fdd3ed06d388fe6572e50a22e9320dfa5nd * - Command-line flags have been removed since they will never be used here.