mod_mime_magic.xml revision 6fbd2e53c97ea6976d93e0ac521adabc55e0fb73
6aada32e978e09cc60d52cb05ae4cee91b676da1slive<!DOCTYPE modulesynopsis SYSTEM "/style/modulesynopsis.dtd">
e942c741056732f50da2074b36fe59805d370650slive<?xml-stylesheet type="text/xsl" href="/style/manual.en.xsl"?>
6fbd2e53c97ea6976d93e0ac521adabc55e0fb73nd Copyright 2002-2004 The Apache Software Foundation
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd Licensed under the Apache License, Version 2.0 (the "License");
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd you may not use this file except in compliance with the License.
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd You may obtain a copy of the License at
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd Unless required by applicable law or agreed to in writing, software
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd distributed under the License is distributed on an "AS IS" BASIS,
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd See the License for the specific language governing permissions and
d5d794fc2f4cc9ca6d6da17cfa2cdcd8d244bacdnd limitations under the License.
6aada32e978e09cc60d52cb05ae4cee91b676da1slive<description>Determines the MIME type of a file
6aada32e978e09cc60d52cb05ae4cee91b676da1slive by looking at a few bytes of its contents</description>
6aada32e978e09cc60d52cb05ae4cee91b676da1slive <p>This module determines the MIME type of files in the same
07f5288fadff97f167db29e52b48a1563a162748nd way the Unix <code>file(1)</code> command works: it looks at the first
07f5288fadff97f167db29e52b48a1563a162748nd few bytes of the file. It is intended as a "second line of defense"
07f5288fadff97f167db29e52b48a1563a162748nd for cases that <module>mod_mime</module> can't resolve.</p>
6aada32e978e09cc60d52cb05ae4cee91b676da1slive <p>This module is derived from a free version of the
6aada32e978e09cc60d52cb05ae4cee91b676da1slive <code>file(1)</code> command for Unix, which uses "magic
6aada32e978e09cc60d52cb05ae4cee91b676da1slive numbers" and other hints from a file's contents to figure out
6aada32e978e09cc60d52cb05ae4cee91b676da1slive what the contents are. This module is active only if the magic
6aada32e978e09cc60d52cb05ae4cee91b676da1slive file is specified by the <directive module="mod_mime_magic"
07f5288fadff97f167db29e52b48a1563a162748nd<section id="format"><title>Format of the Magic File</title>
6aada32e978e09cc60d52cb05ae4cee91b676da1slive <p>The contents of the file are plain ASCII text in 4-5
6aada32e978e09cc60d52cb05ae4cee91b676da1slive columns. Blank lines are allowed but ignored. Commented lines
07f5288fadff97f167db29e52b48a1563a162748nd use a hash mark (<code>#</code>). The remaining lines are parsed for
07f5288fadff97f167db29e52b48a1563a162748nd the following columns:</p>
07f5288fadff97f167db29e52b48a1563a162748nd "<code>></code>" indicates a dependency upon the previous
07f5288fadff97f167db29e52b48a1563a162748nd <td>type of data to match
07f5288fadff97f167db29e52b48a1563a162748nd <td>long integer date (seconds since Unix epoch/1970)</td></tr>
6aada32e978e09cc60d52cb05ae4cee91b676da1slive <p>For example, the following magic file lines would recognize
07f5288fadff97f167db29e52b48a1563a162748nd some audio formats:</p>
07f5288fadff97f167db29e52b48a1563a162748nd0 string .snd
07f5288fadff97f167db29e52b48a1563a162748nd </example>
07f5288fadff97f167db29e52b48a1563a162748nd <p>Or these would recognize the difference between <code>*.doc</code>
07f5288fadff97f167db29e52b48a1563a162748nd files containing Microsoft Word or FrameMaker documents. (These are
6aada32e978e09cc60d52cb05ae4cee91b676da1slive incompatible file formats which use the same file suffix.)</p>
07f5288fadff97f167db29e52b48a1563a162748nd<pre># Frame
07f5288fadff97f167db29e52b48a1563a162748nd </example>
6aada32e978e09cc60d52cb05ae4cee91b676da1slive <p>An optional MIME encoding can be included as a fifth column.
6aada32e978e09cc60d52cb05ae4cee91b676da1slive For example, this can recognize gzipped files and set the
6aada32e978e09cc60d52cb05ae4cee91b676da1slive encoding for them.</p>
07f5288fadff97f167db29e52b48a1563a162748nd<pre># gzip (GNU zip, not to be confused with
07f5288fadff97f167db29e52b48a1563a162748nd </example>
07f5288fadff97f167db29e52b48a1563a162748nd<section id="performance"><title>Performance Issues</title>
6aada32e978e09cc60d52cb05ae4cee91b676da1slive <p>This module is not for every system. If your system is barely
6aada32e978e09cc60d52cb05ae4cee91b676da1slive keeping up with its load or if you're performing a web server
6aada32e978e09cc60d52cb05ae4cee91b676da1slive benchmark, you may not want to enable this because the
6aada32e978e09cc60d52cb05ae4cee91b676da1slive processing is not free.</p>
6aada32e978e09cc60d52cb05ae4cee91b676da1slive <p>However, an effort was made to improve the performance of
07f5288fadff97f167db29e52b48a1563a162748nd the original <code>file(1)</code> code to make it fit in a busy web
07f5288fadff97f167db29e52b48a1563a162748nd server. It was designed for a server where there are thousands of users
6aada32e978e09cc60d52cb05ae4cee91b676da1slive who publish their own documents. This is probably very common
6aada32e978e09cc60d52cb05ae4cee91b676da1slive on intranets. Many times, it's helpful if the server can make
6aada32e978e09cc60d52cb05ae4cee91b676da1slive more intelligent decisions about a file's contents than the
6aada32e978e09cc60d52cb05ae4cee91b676da1slive file name allows ...even if just to reduce the "why doesn't my
6aada32e978e09cc60d52cb05ae4cee91b676da1slive page work" calls when users improperly name their own files.
6aada32e978e09cc60d52cb05ae4cee91b676da1slive You have to decide if the extra work suits your
6aada32e978e09cc60d52cb05ae4cee91b676da1slive environment.</p>
07f5288fadff97f167db29e52b48a1563a162748nd <p>The following notes apply to the <module>mod_mime_magic</module>
07f5288fadff97f167db29e52b48a1563a162748nd module and are included here for compliance with contributors'
07f5288fadff97f167db29e52b48a1563a162748nd copyright restrictions that require their acknowledgment.</p>
07f5288fadff97f167db29e52b48a1563a162748nd <p>mod_mime_magic: MIME type lookup via file magic numbers<br />
07f5288fadff97f167db29e52b48a1563a162748nd Copyright (c) 1996-1997 Cisco Systems, Inc.</p>
07f5288fadff97f167db29e52b48a1563a162748nd <p>This software was submitted by Cisco Systems to the Apache Group
07f5288fadff97f167db29e52b48a1563a162748nd in July 1997. Future revisions and derivatives of this source code
07f5288fadff97f167db29e52b48a1563a162748nd must acknowledge Cisco Systems as the original contributor of this
07f5288fadff97f167db29e52b48a1563a162748nd module. All other licensing and usage conditions are those of the
07f5288fadff97f167db29e52b48a1563a162748nd Apache Group.</p>
07f5288fadff97f167db29e52b48a1563a162748nd <p>Some of this code is derived from the free version of the file
07f5288fadff97f167db29e52b48a1563a162748nd command originally posted to comp.sources.unix. Copyright info for
07f5288fadff97f167db29e52b48a1563a162748nd that program is included below as required.</p>
07f5288fadff97f167db29e52b48a1563a162748nd <p> - Copyright (c) Ian F. Darwin, 1987. Written by Ian F. Darwin.</p>
07f5288fadff97f167db29e52b48a1563a162748nd <p>This software is not subject to any license of the American
07f5288fadff97f167db29e52b48a1563a162748nd Telephone and Telegraph Company or of the Regents of the University
07f5288fadff97f167db29e52b48a1563a162748nd of California.</p>
07f5288fadff97f167db29e52b48a1563a162748nd <p>Permission is granted to anyone to use this software for any
07f5288fadff97f167db29e52b48a1563a162748nd purpose on any computer system, and to alter it and redistribute it
07f5288fadff97f167db29e52b48a1563a162748nd freely, subject to the following restrictions:</p>
07f5288fadff97f167db29e52b48a1563a162748nd <li>The author is not responsible for the consequences of use of
07f5288fadff97f167db29e52b48a1563a162748nd this software, no matter how awful, even if they arise from flaws
07f5288fadff97f167db29e52b48a1563a162748nd in it.</li>
07f5288fadff97f167db29e52b48a1563a162748nd <li>The origin of this software must not be misrepresented, either
07f5288fadff97f167db29e52b48a1563a162748nd by explicit claim or by omission. Since few users ever read
07f5288fadff97f167db29e52b48a1563a162748nd sources, credits must appear in the documentation.</li>
07f5288fadff97f167db29e52b48a1563a162748nd <li>Altered versions must be plainly marked as such, and must not
07f5288fadff97f167db29e52b48a1563a162748nd be misrepresented as being the original software. Since few users
07f5288fadff97f167db29e52b48a1563a162748nd ever read sources, credits must appear in the documentation.</li>
07f5288fadff97f167db29e52b48a1563a162748nd <p>For compliance with Mr Darwin's terms: this has been very
07f5288fadff97f167db29e52b48a1563a162748nd significantly modified from the free "file" command.</p>
07f5288fadff97f167db29e52b48a1563a162748nd <li>all-in-one file for compilation convenience when moving from
07f5288fadff97f167db29e52b48a1563a162748nd one version of Apache to the next.</li>
07f5288fadff97f167db29e52b48a1563a162748nd <li>Memory allocation is done through the Apache API's pool
07f5288fadff97f167db29e52b48a1563a162748nd structure.</li>
07f5288fadff97f167db29e52b48a1563a162748nd <li>All functions have had necessary Apache API request or server
07f5288fadff97f167db29e52b48a1563a162748nd structures passed to them where necessary to call other Apache API
07f5288fadff97f167db29e52b48a1563a162748nd routines. (<em>i.e.</em>, usually for logging, files, or memory
07f5288fadff97f167db29e52b48a1563a162748nd allocation in itself or a called function.)</li>
07f5288fadff97f167db29e52b48a1563a162748nd <li>struct magic has been converted from an array to a single-ended
07f5288fadff97f167db29e52b48a1563a162748nd linked list because it only grows one record at a time, it's only
07f5288fadff97f167db29e52b48a1563a162748nd accessed sequentially, and the Apache API has no equivalent of
07f5288fadff97f167db29e52b48a1563a162748nd <li>Functions have been changed to get their parameters from the
07f5288fadff97f167db29e52b48a1563a162748nd server configuration instead of globals. (It should be reentrant
07f5288fadff97f167db29e52b48a1563a162748nd now but has not been tested in a threaded environment.)</li>
07f5288fadff97f167db29e52b48a1563a162748nd <li>Places where it used to print results to stdout now saves them
07f5288fadff97f167db29e52b48a1563a162748nd in a list where they're used to set the MIME type in the Apache
07f5288fadff97f167db29e52b48a1563a162748nd request record.</li>
07f5288fadff97f167db29e52b48a1563a162748nd <li>Command-line flags have been removed since they will never be
07f5288fadff97f167db29e52b48a1563a162748nd used here.</li>
6aada32e978e09cc60d52cb05ae4cee91b676da1slive<directivesynopsis>
6aada32e978e09cc60d52cb05ae4cee91b676da1slive<description>Enable MIME-type determination based on file contents
6aada32e978e09cc60d52cb05ae4cee91b676da1sliveusing the specified magic file</description>
07f5288fadff97f167db29e52b48a1563a162748nd<contextlist><context>server config</context><context>virtual host</context>
07f5288fadff97f167db29e52b48a1563a162748nd</contextlist>
6aada32e978e09cc60d52cb05ae4cee91b676da1slive <p>The <directive>MimeMagicFile</directive> directive can be used to
6aada32e978e09cc60d52cb05ae4cee91b676da1slive enable this module, the default file is distributed at
6aada32e978e09cc60d52cb05ae4cee91b676da1slive <code>conf/magic</code>. Non-rooted paths are relative to the
07f5288fadff97f167db29e52b48a1563a162748nd <directive module="core">ServerRoot</directive>. Virtual hosts will use
07f5288fadff97f167db29e52b48a1563a162748nd the same file as the main server unless a more specific setting is
07f5288fadff97f167db29e52b48a1563a162748nd used, in which case the more specific setting overrides the main
07f5288fadff97f167db29e52b48a1563a162748nd server's file.</p>
07f5288fadff97f167db29e52b48a1563a162748nd </example>
6aada32e978e09cc60d52cb05ae4cee91b676da1slive</directivesynopsis>
07f5288fadff97f167db29e52b48a1563a162748nd</modulesynopsis>