Blame docs/manual/mod/mod_mime_magic.html.en

Packit 90a5c9
Packit 90a5c9
Packit 90a5c9
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head>
Packit 90a5c9
<meta content="text/html; charset=ISO-8859-1" http-equiv="Content-Type" />
Packit 90a5c9
Packit 90a5c9
        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Packit 90a5c9
              This file is generated from xml source: DO NOT EDIT
Packit 90a5c9
        XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
Packit 90a5c9
      -->
Packit 90a5c9
<title>mod_mime_magic - Apache HTTP Server Version 2.4</title>
Packit 90a5c9
<link href="../style/css/manual.css" rel="stylesheet" media="all" type="text/css" title="Main stylesheet" />
Packit 90a5c9
<link href="../style/css/manual-loose-100pc.css" rel="alternate stylesheet" media="all" type="text/css" title="No Sidebar - Default font size" />
Packit 90a5c9
<link href="../style/css/manual-print.css" rel="stylesheet" media="print" type="text/css" /><link rel="stylesheet" type="text/css" href="../style/css/prettify.css" />
Packit 90a5c9
<script src="../style/scripts/prettify.min.js" type="text/javascript">
Packit 90a5c9
</script>
Packit 90a5c9
Packit 90a5c9
<link href="../images/favicon.ico" rel="shortcut icon" /></head>
Packit 90a5c9
<body>
Packit 90a5c9
Packit 90a5c9

Modules | Directives | FAQ | Glossary | Sitemap

Packit 90a5c9

Apache HTTP Server Version 2.4

Packit 90a5c9
Packit 90a5c9
<-
Packit 90a5c9
Packit 90a5c9
Apache > HTTP Server > Documentation > Version 2.4 > Modules
Packit 90a5c9
Packit 90a5c9

Apache Module mod_mime_magic

Packit 90a5c9
Packit 90a5c9

Available Languages:  en  |

Packit 90a5c9
 fr 

Packit 90a5c9
Packit 90a5c9
Description:Determines the MIME type of a file
Packit 90a5c9
    by looking at a few bytes of its contents
Packit 90a5c9
Status:Extension
Packit 90a5c9
Module Identifier:mime_magic_module
Packit 90a5c9
Source File:mod_mime_magic.c
Packit 90a5c9

Summary

Packit 90a5c9
Packit 90a5c9
    

This module determines the MIME

Packit 90a5c9
    type of files in the same way the Unix
Packit 90a5c9
    file(1) command works: it looks at the first few
Packit 90a5c9
    bytes of the file. It is intended as a "second line of defense"
Packit 90a5c9
    for cases that mod_mime can't resolve.

Packit 90a5c9
Packit 90a5c9
    

This module is derived from a free version of the

Packit 90a5c9
    file(1) command for Unix, which uses "magic
Packit 90a5c9
    numbers" and other hints from a file's contents to figure out
Packit 90a5c9
    what the contents are. This module is active only if the magic
Packit 90a5c9
    file is specified by the MimeMagicFile directive.

Packit 90a5c9
Packit 90a5c9
Support Apache!

Topics

Packit 90a5c9
    Packit 90a5c9
  • Format of the Magic File
  • Packit 90a5c9
  • Performance Issues
  • Packit 90a5c9
  • Notes
  • Packit 90a5c9

    Directives

    Packit 90a5c9
      Packit 90a5c9
    • MimeMagicFile
    • Packit 90a5c9
      Packit 90a5c9

      Bugfix checklist

      See also

      Packit 90a5c9
        Packit 90a5c9
      • Comments
      • Packit 90a5c9
        top
        Packit 90a5c9
        Packit 90a5c9

        Format of the Magic File

        Packit 90a5c9
        Packit 90a5c9
            

        The contents of the file are plain ASCII text in 4-5

        Packit 90a5c9
            columns. Blank lines are allowed but ignored. Commented lines
        Packit 90a5c9
            use a hash mark (#). The remaining lines are parsed for
        Packit 90a5c9
            the following columns:

        Packit 90a5c9
        Packit 90a5c9
            
        ColumnDescription
        Packit 90a5c9
        1
        Packit 90a5c9
                byte number to begin checking from
        Packit 90a5c9
                 ">" indicates a dependency upon the previous
        Packit 90a5c9
                 non-">" line
        Packit 90a5c9
        2
        Packit 90a5c9
                

        type of data to match

        Packit 90a5c9
                
        Packit 90a5c9
                
        Packit 90a5c9
                byte
        Packit 90a5c9
                    single character
        Packit 90a5c9
                short
        Packit 90a5c9
                    machine-order 16-bit integer
        Packit 90a5c9
                long
        Packit 90a5c9
                    machine-order 32-bit integer
        Packit 90a5c9
                string
        Packit 90a5c9
                    arbitrary-length string
        Packit 90a5c9
                date
        Packit 90a5c9
                    long integer date (seconds since Unix epoch/1970)
        Packit 90a5c9
                beshort
        Packit 90a5c9
                    big-endian 16-bit integer
        Packit 90a5c9
                belong
        Packit 90a5c9
                    big-endian 32-bit integer
        Packit 90a5c9
                bedate
        Packit 90a5c9
                    big-endian 32-bit integer date
        Packit 90a5c9
                leshort
        Packit 90a5c9
                    little-endian 16-bit integer
        Packit 90a5c9
                lelong
        Packit 90a5c9
                    little-endian 32-bit integer
        Packit 90a5c9
                ledate
        Packit 90a5c9
                    little-endian 32-bit integer date
        Packit 90a5c9
                
        Packit 90a5c9
        3
        Packit 90a5c9
                contents of data to match
        Packit 90a5c9
        4
        Packit 90a5c9
                MIME type if matched
        Packit 90a5c9
        5
        Packit 90a5c9
                MIME encoding if matched (optional)
        Packit 90a5c9
        Packit 90a5c9
        Packit 90a5c9
            

        For example, the following magic file lines would recognize

        Packit 90a5c9
            some audio formats:

        Packit 90a5c9
        Packit 90a5c9
            
        # Sun/NeXT audio data
        Packit 90a5c9
        0      string      .snd
        Packit 90a5c9
        >12    belong      1       audio/basic
        Packit 90a5c9
        >12    belong      2       audio/basic
        Packit 90a5c9
        >12    belong      3       audio/basic
        Packit 90a5c9
        >12    belong      4       audio/basic
        Packit 90a5c9
        >12    belong      5       audio/basic
        Packit 90a5c9
        >12    belong      6       audio/basic
        Packit 90a5c9
        >12    belong      7       audio/basic
        Packit 90a5c9
        >12    belong     23       audio/x-adpcm
        Packit 90a5c9
        Packit 90a5c9
            

        Or these would recognize the difference between *.doc

        Packit 90a5c9
            files containing Microsoft Word or FrameMaker documents. (These are
        Packit 90a5c9
            incompatible file formats which use the same file suffix.)

        Packit 90a5c9
        Packit 90a5c9
            
        # Frame
        Packit 90a5c9
        0  string  \<MakerFile        application/x-frame
        Packit 90a5c9
        0  string  \<MIFFile          application/x-frame
        Packit 90a5c9
        0  string  \<MakerDictionary  application/x-frame
        Packit 90a5c9
        0  string  \<MakerScreenFon   application/x-frame
        Packit 90a5c9
        0  string  \<MML              application/x-frame
        Packit 90a5c9
        0  string  \<Book             application/x-frame
        Packit 90a5c9
        0  string  \<Maker            application/x-frame
        Packit 90a5c9
        Packit 90a5c9
        # MS-Word
        Packit 90a5c9
        0  string  \376\067\0\043            application/msword
        Packit 90a5c9
        0  string  \320\317\021\340\241\261  application/msword
        Packit 90a5c9
        0  string  \333\245-\0\0\0           application/msword
        Packit 90a5c9
        Packit 90a5c9
            

        An optional MIME encoding can be included as a fifth column.

        Packit 90a5c9
            For example, this can recognize gzipped files and set the
        Packit 90a5c9
            encoding for them.

        Packit 90a5c9
        Packit 90a5c9
            
        # gzip (GNU zip, not to be confused with
        Packit 90a5c9
        #       [Info-ZIP/PKWARE] zip archiver)
        Packit 90a5c9
        Packit 90a5c9
        0  string  \037\213  application/octet-stream  x-gzip
        Packit 90a5c9
        top
        Packit 90a5c9
        Packit 90a5c9

        Performance Issues

        Packit 90a5c9
            

        This module is not for every system. If your system is barely

        Packit 90a5c9
            keeping up with its load or if you're performing a web server
        Packit 90a5c9
            benchmark, you may not want to enable this because the
        Packit 90a5c9
            processing is not free.

        Packit 90a5c9
        Packit 90a5c9
            

        However, an effort was made to improve the performance of

        Packit 90a5c9
            the original file(1) code to make it fit in a busy web
        Packit 90a5c9
            server. It was designed for a server where there are thousands of users
        Packit 90a5c9
            who publish their own documents. This is probably very common
        Packit 90a5c9
            on intranets. Many times, it's helpful if the server can make
        Packit 90a5c9
            more intelligent decisions about a file's contents than the
        Packit 90a5c9
            file name allows ...even if just to reduce the "why doesn't my
        Packit 90a5c9
            page work" calls when users improperly name their own files.
        Packit 90a5c9
            You have to decide if the extra work suits your
        Packit 90a5c9
            environment.

        Packit 90a5c9
        top
        Packit 90a5c9
        Packit 90a5c9

        Notes

        Packit 90a5c9
            

        The following notes apply to the mod_mime_magic

        Packit 90a5c9
            module and are included here for compliance with contributors'
        Packit 90a5c9
            copyright restrictions that require their acknowledgment.

        Packit 90a5c9
        Packit 90a5c9
            
        Packit 90a5c9
              

        mod_mime_magic: MIME type lookup via file magic numbers

        Packit 90a5c9
              Copyright (c) 1996-1997 Cisco Systems, Inc.

        Packit 90a5c9
        Packit 90a5c9
              

        This software was submitted by Cisco Systems to the Apache Group

        Packit 90a5c9
              in July 1997. Future revisions and derivatives of this source code
        Packit 90a5c9
              must acknowledge Cisco Systems as the original contributor of this
        Packit 90a5c9
              module. All other licensing and usage conditions are those of the
        Packit 90a5c9
              Apache Group.

        Packit 90a5c9
        Packit 90a5c9
              

        Some of this code is derived from the free version of the file

        Packit 90a5c9
              command originally posted to comp.sources.unix. Copyright info for
        Packit 90a5c9
              that program is included below as required.

        Packit 90a5c9
            
        Packit 90a5c9
        Packit 90a5c9
            
        Packit 90a5c9
              

        - Copyright (c) Ian F. Darwin, 1987. Written by Ian F. Darwin.

        Packit 90a5c9
        Packit 90a5c9
              

        This software is not subject to any license of the American

        Packit 90a5c9
              Telephone and Telegraph Company or of the Regents of the University
        Packit 90a5c9
              of California.

        Packit 90a5c9
        Packit 90a5c9
              

        Permission is granted to anyone to use this software for any

        Packit 90a5c9
              purpose on any computer system, and to alter it and redistribute it
        Packit 90a5c9
              freely, subject to the following restrictions:

        Packit 90a5c9
        Packit 90a5c9
              
          Packit 90a5c9
                  
        1. The author is not responsible for the consequences of use of
        2. Packit 90a5c9
                  this software, no matter how awful, even if they arise from flaws
          Packit 90a5c9
                  in it.
          Packit 90a5c9
          Packit 90a5c9
                  
        3. The origin of this software must not be misrepresented, either
        4. Packit 90a5c9
                  by explicit claim or by omission. Since few users ever read
          Packit 90a5c9
                  sources, credits must appear in the documentation.
          Packit 90a5c9
          Packit 90a5c9
                  
        5. Altered versions must be plainly marked as such, and must not
        6. Packit 90a5c9
                  be misrepresented as being the original software. Since few users
          Packit 90a5c9
                  ever read sources, credits must appear in the documentation.
          Packit 90a5c9
          Packit 90a5c9
                  
        7. This notice may not be removed or altered.
        8. Packit 90a5c9
                
          Packit 90a5c9
              
          Packit 90a5c9
          Packit 90a5c9
              
          Packit 90a5c9
                

          For compliance with Mr Darwin's terms: this has been very

          Packit 90a5c9
                significantly modified from the free "file" command.

          Packit 90a5c9
          Packit 90a5c9
                
            Packit 90a5c9
                    
          • all-in-one file for compilation convenience when moving from
          • Packit 90a5c9
                    one version of Apache to the next.
            Packit 90a5c9
            Packit 90a5c9
                    
          • Memory allocation is done through the Apache API's pool
          • Packit 90a5c9
                    structure.
            Packit 90a5c9
            Packit 90a5c9
                    
          • All functions have had necessary Apache API request or server
          • Packit 90a5c9
                    structures passed to them where necessary to call other Apache API
            Packit 90a5c9
                    routines. (i.e., usually for logging, files, or memory
            Packit 90a5c9
                    allocation in itself or a called function.)
            Packit 90a5c9
            Packit 90a5c9
                    
          • struct magic has been converted from an array to a single-ended
          • Packit 90a5c9
                    linked list because it only grows one record at a time, it's only
            Packit 90a5c9
                    accessed sequentially, and the Apache API has no equivalent of
            Packit 90a5c9
                    realloc().
            Packit 90a5c9
            Packit 90a5c9
                    
          • Functions have been changed to get their parameters from the
          • Packit 90a5c9
                    server configuration instead of globals.  (It should be reentrant
            Packit 90a5c9
                    now but has not been tested in a threaded environment.)
            Packit 90a5c9
            Packit 90a5c9
                    
          • Places where it used to print results to stdout now saves them
          • Packit 90a5c9
                    in a list where they're used to set the MIME type in the Apache
            Packit 90a5c9
                    request record.
            Packit 90a5c9
            Packit 90a5c9
                    
          • Command-line flags have been removed since they will never be
          • Packit 90a5c9
                    used here.
            Packit 90a5c9
                  
            Packit 90a5c9
                
            Packit 90a5c9
            Packit 90a5c9
            top
            Packit 90a5c9
            Packit 90a5c9
            Packit 90a5c9
            Description:Enable MIME-type determination based on file contents
            Packit 90a5c9
            using the specified magic file
            Packit 90a5c9
            Syntax:MimeMagicFile file-path
            Packit 90a5c9
            Context:server config, virtual host
            Packit 90a5c9
            Status:Extension
            Packit 90a5c9
            Module:mod_mime_magic
            Packit 90a5c9
            Packit 90a5c9
                

            The MimeMagicFile directive can be used to

            Packit 90a5c9
                enable this module, the default file is distributed at
            Packit 90a5c9
                conf/magic. Non-rooted paths are relative to the
            Packit 90a5c9
                ServerRoot. Virtual hosts will use
            Packit 90a5c9
                the same file as the main server unless a more specific setting is
            Packit 90a5c9
                used, in which case the more specific setting overrides the main
            Packit 90a5c9
                server's file.

            Packit 90a5c9
            Packit 90a5c9
                

            Example

            MimeMagicFile conf/magic
            Packit 90a5c9
            Packit 90a5c9
            Packit 90a5c9
            Packit 90a5c9
            Packit 90a5c9
            Packit 90a5c9

            Available Languages:  en  |

            Packit 90a5c9
             fr 

            Packit 90a5c9
            top

            Comments

            Notice:
            This is not a Q&A section. Comments placed here should be pointed towards suggestions on improving the documentation or server, and may be removed again by our moderators if they are either implemented or considered invalid/off-topic. Questions on how to manage the Apache HTTP Server should be directed at either our IRC channel, #httpd, on Freenode, or sent to our mailing lists.
            Packit 90a5c9
            <script type="text/javascript">
            Packit 90a5c9
            var comments_shortname = 'httpd';
            Packit 90a5c9
            var comments_identifier = 'http://httpd.apache.org/docs/2.4/mod/mod_mime_magic.html';
            Packit 90a5c9
            (function(w, d) {
            Packit 90a5c9
                if (w.location.hostname.toLowerCase() == "httpd.apache.org") {
            Packit 90a5c9
                    d.write('
            <\/div>');
            Packit 90a5c9
                    var s = d.createElement('script');
            Packit 90a5c9
                    s.type = 'text/javascript';
            Packit 90a5c9
                    s.async = true;
            Packit 90a5c9
                    s.src = 'https://comments.apache.org/show_comments.lua?site=' + comments_shortname + '&page=' + comments_identifier;
            Packit 90a5c9
                    (d.getElementsByTagName('head')[0] || d.getElementsByTagName('body')[0]).appendChild(s);
            Packit 90a5c9
                }
            Packit 90a5c9
                else { 
            Packit 90a5c9
                    d.write('
            Comments are disabled for this page at the moment.<\/div>');
            Packit 90a5c9
                }
            Packit 90a5c9
            })(window, document);
            Packit 90a5c9
            //--></script>
            Packit 90a5c9

            Copyright 2018 The Apache Software Foundation.
            Licensed under the Apache License, Version 2.0.

            Packit 90a5c9

            Modules | Directives | FAQ | Glossary | Sitemap

            <script type="text/javascript">
            Packit 90a5c9
            if (typeof(prettyPrint) !== 'undefined') {
            Packit 90a5c9
                prettyPrint();
            Packit 90a5c9
            }
            Packit 90a5c9
            //--></script>
            Packit 90a5c9
            </body></html>