mod_mime_magic.html revision 240a5b8962329911d02566b600be6226e1f857ae
715N/A<html xmlns="http://www.w3.org/TR/xhtml1/strict"><head><!--
715N/AXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
715N/A This file is generated from xml source: DO NOT EDIT
715N/AXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
715N/A--><title>mod_mime_magic - Apache HTTP Server</title><link rel="stylesheet" type="text/css" href="/style/manual.css"/></head><body><blockquote><div align="center"><img src="/images/sub.gif" alt="[APACHE DOCUMENTATION]"/><h3>Apache HTTP Server Version 2.0</h3></div><h1 align="center">Apache Module mod_mime_magic</h1><table bgcolor="#cccccc" cellpadding="0" cellspacing="1"><tr><td><table bgcolor="#ffffff"><tr><td valign="top"><span class="help">Description:</span></td><td>Determines the MIME type of a file
715N/A by looking at a few bytes of its contents</td></tr><tr><td><a class="help" href="module-dict.html#Status">Status:</a></td><td>Extension</td></tr><tr><td><a class="help" href="module-dict.html#ModuleIdentifier">Module&nbsp;Identifier:</a></td><td>mime_magic_module</td></tr></table></td></tr></table><h2>Summary</h2>
715N/A <p>This module determines the MIME type of files in the same
715N/A way the Unix file(1) command works: it looks at the first few
715N/A bytes of the file. It is intended as a "second line of defense"
715N/A for cases that <code><a href="mod_mime.html">mod_mime</a></code> can't
715N/A resolve. To assure that mod_mime gets first try at determining
715N/A a file's MIME type, be sure to list mod_mime_magic
715N/A <strong>before</strong> mod_mime in the configuration.</p>
715N/A
715N/A <p>This module is derived from a free version of the
715N/A <code>file(1)</code> command for Unix, which uses "magic
715N/A numbers" and other hints from a file's contents to figure out
715N/A what the contents are. This module is active only if the magic
715N/A file is specified by the <a class="directive" href="#mimemagicfile"><code class="directive">MimeMagicFile</code></a> directive.</p>
715N/A<h2>Directives</h2><ul><li><a href="#mimemagicfile">MimeMagicFile</a></li></ul><h2>Format of the Magic File</h2>
1374N/A
715N/A <p>The contents of the file are plain ASCII text in 4-5
715N/A columns. Blank lines are allowed but ignored. Commented lines
715N/A use a hash mark "#". The remaining lines are parsed for the
715N/A following columns:</p>
715N/A
858N/A <table border="1">
857N/A <tr valign="top">
715N/A <th>Column</th>
715N/A
715N/A <th>Description</th>
715N/A </tr>
1374N/A
715N/A <tr valign="top">
715N/A <td>1</td>
1459N/A
715N/A <td>byte number to begin checking from<br/>
1460N/A "&gt;" indicates a dependency upon the previous non-"&gt;"
715N/A line</td>
844N/A </tr>
1474N/A
761N/A <tr valign="top">
761N/A <td>2</td>
715N/A
803N/A <td>
844N/A type of data to match
851N/A
788N/A <table border="1">
788N/A <tr>
1327N/A <td>byte</td>
760N/A
715N/A <td>single character</td>
726N/A </tr>
726N/A
726N/A <tr>
1195N/A <td>short</td>
715N/A
715N/A <td>machine-order 16-bit integer</td>
715N/A </tr>
1474N/A
1474N/A <tr>
899N/A <td>long</td>
899N/A
717N/A <td>machine-order 32-bit integer</td>
747N/A </tr>
747N/A
844N/A <tr>
844N/A <td>string</td>
747N/A
747N/A <td>arbitrary-length string</td>
788N/A </tr>
788N/A
788N/A <tr>
788N/A <td>date</td>
788N/A
788N/A <td>long integer date (seconds since Unix
856N/A epoch/1970)</td>
856N/A </tr>
856N/A
856N/A <tr>
856N/A <td>beshort</td>
856N/A
715N/A <td>big-endian 16-bit integer</td>
715N/A </tr>
760N/A
760N/A <tr>
760N/A <td>belong</td>
851N/A
851N/A <td>big-endian 32-bit integer</td>
851N/A </tr>
851N/A
851N/A <tr>
851N/A <td>bedate</td>
851N/A
851N/A <td>big-endian 32-bit integer date</td>
851N/A </tr>
898N/A
898N/A <tr>
898N/A <td>leshort</td>
864N/A
864N/A <td>little-endian 16-bit integer</td>
864N/A </tr>
803N/A
1238N/A <tr>
803N/A <td>lelong</td>
1182N/A
857N/A <td>little-endian 32-bit integer</td>
803N/A </tr>
857N/A
857N/A <tr>
857N/A <td>ledate</td>
803N/A
810N/A <td>little-endian 32-bit integer date</td>
860N/A </tr>
1195N/A </table>
803N/A </td>
803N/A </tr>
803N/A
760N/A <tr valign="top">
760N/A <td>3</td>
760N/A
760N/A <td>contents of data to match</td>
1470N/A </tr>
1470N/A
760N/A <tr valign="top">
760N/A <td>4</td>
760N/A
760N/A <td>MIME type if matched</td>
760N/A </tr>
760N/A
760N/A <tr valign="top">
760N/A <td>5</td>
760N/A
760N/A <td>MIME encoding if matched (optional)</td>
760N/A </tr>
760N/A </table>
760N/A
788N/A <p>For example, the following magic file lines would recognize
887N/A some audio formats.</p>
887N/A<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
887N/A<pre>
887N/A# Sun/NeXT audio data
887N/A0 string .snd
887N/A&gt;12 belong 1 audio/basic
887N/A&gt;12 belong 2 audio/basic
887N/A&gt;12 belong 3 audio/basic
887N/A&gt;12 belong 4 audio/basic
887N/A&gt;12 belong 5 audio/basic
788N/A&gt;12 belong 6 audio/basic
788N/A&gt;12 belong 7 audio/basic
788N/A&gt;12 belong 23 audio/x-adpcm
788N/A</pre>
788N/A</code></td></tr></table></blockquote>
788N/A <p>Or these would recognize the difference between "*.doc" files
788N/A containing Microsoft Word or FrameMaker documents. (These are
788N/A incompatible file formats which use the same file suffix.)</p>
788N/A<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
788N/A<pre>
1474N/A# Frame
1474N/A0 string \&lt;MakerFile application/x-frame
793N/A0 string \&lt;MIFFile application/x-frame
1374N/A0 string \&lt;MakerDictionary application/x-frame
1374N/A0 string \&lt;MakerScreenFon application/x-frame
1374N/A0 string \&lt;MML application/x-frame
1374N/A0 string \&lt;Book application/x-frame
793N/A0 string \&lt;Maker application/x-frame
1374N/A
793N/A# MS-Word
793N/A0 string \376\067\0\043 application/msword
788N/A0 string \320\317\021\340\241\261 application/msword
1327N/A0 string \333\245-\0\0\0 application/msword
793N/A</pre>
793N/A</code></td></tr></table></blockquote>
788N/A <p>An optional MIME encoding can be included as a fifth column.
788N/A For example, this can recognize gzipped files and set the
788N/A encoding for them.</p>
803N/A<blockquote><table cellpadding="10"><tr><td bgcolor="#eeeeee"><code>
803N/A<pre>
803N/A# gzip (GNU zip, not to be confused with [Info-ZIP/PKWARE] zip archiver)
803N/A0 string \037\213 application/octet-stream x-gzip
803N/A</pre>
803N/A</code></td></tr></table></blockquote>
803N/A<h2>Performance Issues</h2>
803N/A <p>This module is not for every system. If your system is barely
803N/A keeping up with its load or if you're performing a web server
851N/A benchmark, you may not want to enable this because the
715N/A processing is not free.</p>
715N/A
1459N/A <p>However, an effort was made to improve the performance of
1459N/A the original file(1) code to make it fit in a busy web server.
715N/A It was designed for a server where there are thousands of users
726N/A who publish their own documents. This is probably very common
715N/A on intranets. Many times, it's helpful if the server can make
717N/A more intelligent decisions about a file's contents than the
803N/A file name allows ...even if just to reduce the "why doesn't my
715N/A page work" calls when users improperly name their own files.
715N/A You have to decide if the extra work suits your
844N/A environment.</p>
844N/A
844N/A <p>When compiling an Apache server, this module should be at or
844N/A near the top of the list of modules in the Configuration file.
1459N/A The modules are listed in increasing priority so that will mean
1459N/A this one is used only as a last resort, just like it was
1459N/A designed to.</p>
1459N/A
1459N/A<h2><a name="notes">Notes</a></h2>
1459N/A
1459N/A <p>The following notes apply to the mod_mime_magic module and are
1459N/A included here for compliance with contributors' copyright
1459N/A restrictions that require their acknowledgment. </p>
717N/A<pre>
803N/A/*
715N/A * mod_mime_magic: MIME type lookup via file magic numbers
715N/A * Copyright (c) 1996-1997 Cisco Systems, Inc.
717N/A *
803N/A * This software was submitted by Cisco Systems to the Apache Group in July
715N/A * 1997. Future revisions and derivatives of this source code must
715N/A * acknowledge Cisco Systems as the original contributor of this module.
717N/A * All other licensing and usage conditions are those of the Apache Group.
803N/A *
841N/A * Some of this code is derived from the free version of the file command
841N/A * originally posted to comp.sources.unix. Copyright info for that program
841N/A * is included below as required.
841N/A * ---------------------------------------------------------------------------
715N/A * - Copyright (c) Ian F. Darwin, 1987. Written by Ian F. Darwin.
715N/A *
844N/A * This software is not subject to any license of the American Telephone and
844N/A * Telegraph Company or of the Regents of the University of California.
844N/A *
844N/A * Permission is granted to anyone to use this software for any purpose on any
717N/A * computer system, and to alter it and redistribute it freely, subject to
803N/A * the following restrictions:
715N/A *
851N/A * 1. The author is not responsible for the consequences of use of this
898N/A * software, no matter how awful, even if they arise from flaws in it.
898N/A *
898N/A * 2. The origin of this software must not be misrepresented, either by
898N/A * explicit claim or by omission. Since few users ever read sources, credits
898N/A * must appear in the documentation.
898N/A *
851N/A * 3. Altered versions must be plainly marked as such, and must not be
851N/A * misrepresented as being the original software. Since few users ever read
851N/A * sources, credits must appear in the documentation.
898N/A *
864N/A * 4. This notice may not be removed or altered.
864N/A * -------------------------------------------------------------------------
864N/A *
864N/A * For compliance with Mr Darwin's terms: this has been very significantly
864N/A * modified from the free "file" command.
864N/A * - all-in-one file for compilation convenience when moving from one
864N/A * version of Apache to the next.
864N/A * - Memory allocation is done through the Apache API's pool structure.
864N/A * - All functions have had necessary Apache API request or server
864N/A * structures passed to them where necessary to call other Apache API
715N/A * routines. (<em>i.e.</em>, usually for logging, files, or memory allocation in
715N/A * itself or a called function.)
1459N/A * - struct magic has been converted from an array to a single-ended linked
1459N/A * list because it only grows one record at a time, it's only accessed
1459N/A * sequentially, and the Apache API has no equivalent of realloc().
1459N/A * - Functions have been changed to get their parameters from the server
1459N/A * configuration instead of globals. (It should be reentrant now but has
1459N/A * not been tested in a threaded environment.)
1459N/A * - Places where it used to print results to stdout now saves them in a
1459N/A * list where they're used to set the MIME type in the Apache request
1459N/A * record.
1459N/A * - Command-line flags have been removed since they will never be used here.
1459N/A *
1459N/A */
1459N/A</pre>
1459N/A<hr/><h2><a name="MimeMagicFile">MimeMagicFile</a> <a name="mimemagicfile">Directive</a></h2><table bgcolor="#cccccc" border="0" cellspacing="0" cellpadding="1"><tr><td><table bgcolor="#ffffff"><tr><td><strong>Description: </strong></td><td>Enable MIME-type determination based on file contents
1459N/Ausing the specified magic file</td></tr><tr><td><a class="help" href="directive-dict.html#Syntax">Syntax:</a></td><td>MimeMagicFile <em>file-path</em></td></tr><tr><td><a class="help" href="directive-dict.html#Context">Context:</a></td><td>server config, virtual host</td></tr><tr><td><a class="help" href="directive-dict.html#Status">Status:</a></td><td>Extension</td></tr><tr><td><a class="help" href="directive-dict.html#Module">Module:</a></td><td>mod_mime_magic</td></tr></table></td></tr></table>
1459N/A <p>The <code class="directive">MimeMagicFile</code> directive can be used to
1459N/A enable this module, the default file is distributed at
1459N/A <code>conf/magic</code>. Non-rooted paths are relative to the
1459N/A ServerRoot. Virtual hosts will use the same file as the main
1459N/A server unless a more specific setting is used, in which case
1459N/A the more specific setting overrides the main server's file.</p>
1459N/A<hr/><h3 align="center">Apache HTTP Server Version 2.0</h3><a href="./"><img src="/images/index.gif" alt="Index"/></a><a href="../"><img src="/images/home.gif" alt="Home"/></a></blockquote></body></html>