¸ðÁú¶ó°¡ MIME Çü½ÄÀ» °áÁ¤ÇÏ´Â ¹æ½Ä
How Mozilla determines MIME Types
ÀÛ¼ºÀÚ : Christian Biesinger <cbiesinger@web.de>¼Ò°³
Introduction
¸ðÁú¶ó¿¡¼ ¸ðµç µ¥ÀÌŸ 󸮴 ³»¿ëÀÇ MIME Çü½Ä¿¡ ±Ù°ÅÇÕ´Ï´Ù. urlÀ» ºÒ·¯µéÀÏ ¶§¸¶´Ù ¸ðÁú¶ó´Â MIME Çü½ÄÀ» ã¾Æ³»¾ß ÇÑ´Ù´Â ÀǹÌÀÔ´Ï´Ù. ÀÌ ¹æ½Ä¿¡ ´ëÇØ ÀÌ ¹®¼¿¡¼ ¼³¸íÇϰí ÀÖ½À´Ï´Ù.
All data handling in Mozilla is based on the MIME type of the
content. This means that every time an url is loaded, Mozilla must find
out its MIME type. The several ways how this happens are described
in this document.
³»¿ë-Çü½Ä "¾Ï½Ã"
Content-Type "hints"
¸ðÁú¶ó´Â "³»¿ë-Çü½Ä ¾Ï½Ã"¶ó´Â °³³äÀ» °¡Áö°íÀÖ½À´Ï´Ù. ¿¹¸¦ µé¾î, ¸ðÁú¶ó°¡ <link type="text/css" type="stylesheet" href="...">¿ä¼Ò¸¦ ¸¸³ª¸é text/css Çü½ÄÀ¸·Î ¹Þ¾ÆµéÀÌ°Ô µË´Ï´Ù. ±×·¯³ª ¼¹ö°¡ Àü¼ÛÇÏ´Â ½ÇÁ¦ MIME Çü½ÄÀ» º¸³½´Ù¸é À̸¦ ¹«½ÃÇØ¹ö¸³´Ï´Ù. (ÀÌ·± Ư¼öÇÑ ¿¹´Â, ¼¹ö ¹«½Ã󸮴 ǥÁØÁؼö ¹æ½ÄÀÇ °æ¿ì¿¡¸¸ ÀϾ´Ï´Ù. ¸ðÁú¶ó ÄõÅ©¹æ½Ä ¶Ç´Â À¥°³¹ßÀÚ FAQ¸¦ Âü°íÇϼ¼¿ä). ¸ðÁú¶ó 1.6 ¾ËÆÄ¹öÀüºÎÅÍ <a href="..." type="foo/bar">¿¡ ´ëÇØ ºñ½ÁÇÑ Ã³¸®¹æ½ÄÀÌ ÀÌ·ç¾îÁý´Ï´Ù.
Mozilla has a concept of "content-type hints". This means that, for
example, if Mozilla encounters a <link type="text/css"
type="stylesheet" href="..."> element, a type of text/css will be
assumed. This is, however, overridden by the actual MIME type the
server sends (if any). (For this specific example, the server override
only happens in standards-compliant mode. See Mozilla's
quirks mode or Web
developer FAQ).
Similar handling happens for <a href="..."
type="foo/bar">, starting in Mozilla 1.6alpha.
HTTP, ¸ÞÀÏ Ã·ºÎÆÄÀÏ
HTTP, Mail Attachments
¸ÞÀÏ Ã·ºÎÆÄÀϻӸ¸ ¾Æ´Ï¶ó HTTP URI¿¡ ´ëÇØ, ¸ðÁú¶ó´Â
´ë°³ÀÇ °æ¿ì ¼¹ö¿¡¼ º¸³½ MIME ŸÀÔÀ» °¡Á®¿Í¼
»ç¿ëÇÕ´Ï´Ù. MSIE(MSIEÀÇ
MIME Çü½Ä ÃßÃø¿¡ °üÇÑ MSDN ¹®¼ÀÚ·á)¿Í´Â ´Þ¸®, ¸ðÁú¶ó´Â
ÀϹÝÀûÀ¸·Î ÇØ´ç ¹®¼¿¡¼ Çü½ÄÀ» ¾Ë¾Æ³»Áö ¾Ê½À´Ï´Ù.
±×·¯³ª ¸ðÁú¶ó 1.7¾ËÆÄºÎÅÍ ¸ðÁú¶ó´Â ´ÙÀ½°ú °°ÀÌ ³»¿ëÀ»
¾Ë¾Æ³»´Â ÀÛ¾÷À» ÇÕ´Ï´Ù:
¼¹ö¿¡¼ Àü¼ÛÇÑ ³»¿ë-Çü½ÄÀÌ (´ë¼Ò¹®ÀÚ±¸ºÐ) text/plain, text/plain; charset=ISO-8859-1
¶Ç´Â text/plain; charset=iso-8859-17ÁßÀÇ ÇϳªÀ̸é¼,
±×¸®°í ÇØ´ç ¼¹ö°¡ ³»¿ë-¿£ÄÚµù ¸Ó¸®¸» Á¤º¸(Content-Encoding
header)¸¦ Àü¼ÛÇÏÁö ¾ÊÀº °æ¿ì, ¸ðÁú¶ó´Â µ¥ÀÌŸÀÇ Ã¹ ±¸¿ªÀ»
¾Ë¾Æ³»¾î ÅØ½ºÆ®°¡ ¾Æ´Ñ ¹ÙÀÌÆ®¸¦ Á¡°ËÇÕ´Ï´Ù. ÅØ½ºÆ®
¹ÙÀÌÆ®´Â 9-13, 27, ±×¸®°í 31-255ÀÔ´Ï´Ù. ÅØ½ºÆ®°¡ ¾Æ´Ñ ¹ÙÀ̸¦
¸¸³¯ °æ¿ì, µµ¿ì¹Ì ´ëÈâ(helper app dialog)¿¡ ÇØ´ç ÆÄÀÏÀÇ
È®ÀåÀÚ¿¡ »óÀÀÇÏ´Â mime-Çü½ÄÀ» º¸¿©ÁÖ°Ô µË´Ï´Ù.
For HTTP URIs, as well as for Mail Attachments, Mozilla usually gets
a MIME type sent from the server, and uses it. Contrary to MSIE (MSDN
Document on MSIE MIME type guessing), Mozilla will generally not sniff the
type of the document. However, starting in Mozilla 1.7alpha, Mozilla does do content sniffing, like this:
When the Content-Type sent by the server is one of (case-sensitively) text/plain, text/plain; charset=ISO-8859-1 or text/plain; charset=iso-8859-1,
and the server did not send a Content-Encoding header, Mozilla will
sniff the first block of data it gets and check for non-text bytes.
Text bytes are 9-13, 27, and 31-255. When encountering a non-text byte,
the helper app dialog will be shown, showing the mime-type
corresponding to the extension of the file.
¶ÇÇÑ <img src>·Î ºÒ·¯µéÀÎ À̹ÌÁöÀÇ °æ¿ì, ¸ðÁú¶óÀÇ À̹ÌÁö ¶óÀ̺귯¸®´Â À̹ÌÁöÀÇ ½ÇÁ¦ Çü½ÄÀ» ã¾Æ³»±â À§ÇØ ÄÁÅÙÃ÷¸¦ ¾Ë¾Æ³»·Á ÇÕ´Ï´Ù.(À̰ÍÀº È®ÀåÀÚ¸¦ ¾Ë¾Æ³»´Â °ÍÀÌ ¾Æ´Ô)
Also, for images loaded via <img src>,
Mozilla's image library will do content sniffing (never extension
sniffing) to find out the real type of the image.
¼¹ö°¡ ³»¿ë-Çü½Ä Çì´õÁ¤º¸¸¦ Àü¼ÛÇÏÁö ¾ÊÀ¸¸é, ¸ðÁú¶ó´Â MIME Çü½ÄÀ» ã¾Æ³»±â À§ÇØ ¾Ë·ÁÁöÁö¾ÊÀº ÇØ¼®±â¸¦ »ç¿ëÇÕ´Ï´Ù.
If the server did not send a Content-Type header, Mozilla uses the unknown decoder to find a MIME type.
ÆÄÀÏ URI
File URIs
ÆÄÀÏ URIÀÇ °æ¿ì ¸ðÁú¶ó´Â MIME Çü½Ä¿¡ ´ëÇØ ¿ÜºÎµµ¿ì¹Ì¼ºñ½º(ExternalHelperAppService)¸¦ ¿äûÇÏ°Ô µË´Ï´Ù.
For file: URIs, Mozilla will ask the ExternalHelperAppService
for a MIME type.
FTP
MIME Çü½ÄÀÌ ¾ø´Â HTTP URIÀÇ °æ¿ì, FTP uri´Â ¾Ë·ÁÁöÁö¾ÊÀº ÇØ¼®±â¸¦ °ÅÄ¡°Ô µË´Ï´Ù.
Like HTTP URIs without a MIME type, FTP uris go through the unknown decoder.
¾Ë·ÁÁöÁö ¾ÊÀº ÇØ¼®±â
Unknown Decoder
netwerk/streamconv/converters/nsUnknownDecoder.cpp¸¦ º¸¸é, 287¹ø Çà¿¡ Èï¹Ì·Î¿î ºÎºÐÀÌ ÀÖ½À´Ï´Ù. sSnifferEntries´Â DetermineContentType ÇÔ¼ö¿Í ÇÔ²² ÀÖ½À´Ï´Ù. À̰ÍÀÌ ÇÏ´Â ÀÛ¾÷Àº ´ÙÀ½°ú °°½À´Ï´Ù:
Located at netwerk/streamconv/converters/nsUnknownDecoder.cpp, the
interesting part starts at line
287, the sSnifferEntries array together with the
DetermineContentType function.
It does the following:
- ÆÄÀÏÀÇ ½ÃÀۺκп¡¼ "¸¶¼úÀÇ ¼ýÀÚ(magic numbers)"¶ó°í ÇÏ´Â °÷À» Á¡°ËÇÕ´Ï´Ù; PDF¿Í Æ÷½ºÆ®½ºÅ©¸³Æ®¸¦ ÇöÀç °¨ÁöÇÒ ¼ö ÀÖ½À´Ï´Ù.
- ÆÄÀÏÀÌ <?xml ·Î ½ÃÀÛÇÑ´Ù¸é, uri¿¡ ¸Â´Â MIME Çü½ÄÀ» ¿ÜºÎµµ¿ì¹Ì¼ºñ½º(ExternalHelperAppService)¿¡ ¿äûÇÕ´Ï´Ù.
- ³»¿ë¹°ÀÌ Á¦°øµÇ¸é À̹ÌÁö ¶óÀ̺귯¸®¿¡ MIME Çü½ÄÀ» ¿äûÇÏ°Ô µË´Ï´Ù. ¸ðÁú¶ó°¡ Áö¿øÇÏ´Â ¸ðµç À̹ÌÁöÀÇ Çü½ÄÀ» ã¾Æ³»´Â µ¥ ½Å·ÚÇÒ¸¸ÇÑ ±â´ÉÀ» Á¦°øÇÕ´Ï´Ù.
- ÀϺÎÀÇ °øÅë HTML ű׸¦ ã¾Æ³»¾î ÇØ´ç µ¥ÀÌŸ°¡ HTMLÀÎ Áö¸¦ Á¡°ËÇÕ´Ï´Ù.
- MIME Çü½Ä ÃßÃøÀ» À§ÇØ URI¸¦ ¿ÜºÎµµ¿ì¹Ì¼ºñ½º(ExternalHelperAppService)¿¡ ³Ñ±é´Ï´Ù.
- ÀÌ·¸°ÔÇØ¼µµ 󸮸¦ ÇÏÁö¸øÇϸé, ÀÓº£µðµå³Î(embedded nulls)·Î ¹öÆÛ(¿¹¸¦ µé¾î ÇØ´ç ÆÄÀÏÀÇ Ã¹ ¸î ¹ÙÀÌÆ®)¸¦ °Ë»öÇÏ¿©, ¾Æ¹«°Íµµ ¾øÀ¸¸é text/plainÀ» »ç¿ëÇϸç, ±×·¸Áö¾ÊÀ¸¸é application/octer-streamÀ» »ç¿ëÇÕ´Ï´Ù.
¡¡
- Checks the start of the file for "magic numbers"; this can currently detect PDF and Postscript.
- If the file starts with <?xml, asks the ExternalHelperAppService
for a MIME type for the uri. This is done because the generic
text/xml MIME type does not work for XUL files, and XHTML files get a
different DOM when interpreted as text/xml.
- The Image Library will be asked for the MIME type given the content. This should allow reliable detection of all image types Mozilla supports.
- Checks whether the data is HTML by looking for some common HTML
tags.
- The URI is handed to the ExternalHelperAppService for MIME type guessing
- If all else fails, the buffer (i.e. the first
few bytes of the file) is searched for embedded nulls; if none are
found,
text/plainwill be used, otherwiseapplication/octet-stream.
¿ÜºÎµµ¿ì¹Ì¼ºñ½º
ExternalHelperAppService
(uriloader/exthandler/nsExternalHelperAppService.cpp¿¡
ÀÖ½À´Ï´Ù)
ÆÄÀÏ -> MIME Çü½Ä ¸ÅÇÎ ÀÛ¾÷Àº ´ÙÀ½°ú °°½À´Ï´Ù:
The file->MIME type mapping works like this:
- BeOS¿¡¼, ¿î¿µ½Ã½ºÅÛ¿¡ ÆÄÀÏ Çü½ÄÀ» ¿äûÇÕ´Ï´Ù (¾ÆÁ÷ ¸¹Áö´Â ¾ÊÁö¸¸, ¹ö±×(217723)°¡ Á¸ÀçÇÑ´Ù)
- MacOS¿¡¼, OS¿¡¼ ÆÄÀÏ Çü½ÄÀ» ã±âÀ§ÇØ Çü½Ä°ú Á¦ÀÛÀÚ Äڵ带 »ç¿ëÇÕ´Ï´Ù.
- È®ÀåÀÚÀÇ ÇϵåÄÚµùµÈ ¸ñ·ÏÀ» üũÇÕ´Ï´Ù.(ÇöÀç 13°³ ¿£Æ®¸®¸¦ °¡Áö°íÀÖ´Ù.http://lxr.mozilla.org/seamonkey/source/uriloader/exthandler/nsExternalHelperAppService.cpp#299)
- È®ÀåÀÚ°¡ ¸ñ·Ï¿¡ ¾øÀ¸¸é, Àç¹ÌÀÖ¾îÁö´Â µ¥. ¸ÕÀú
¿î¿µ½Ã½ºÅÛ¿¡ MIME Çü½ÄÀ» ¿äûÇÕ´Ï´Ù. ±×µµ ¾ÈµÇ¸é,
»ç¿ëÀÚÁ¦°øµµ¿ì¹Ì(user-supplied
helper app)¸¦ È®ÀåÀÚ·Î °Ë»öÇϰí, ±×·¡¼ ÁöÁ¤µÈ MIME Çü½ÄÀ»
»ç¿ëÇÏ°Ô µË´Ï´Ù. (¿¹¸¦ µé¾î, ÆíÁý/ȯ°æ¼³Á¤/µµ¿ì¹Ì
ÇÁ·Î±×·¥(Edit/Preferences/Helper Applications)
À̰͵µ ¾ÈµÇ¸é, È®ÀåÀÚ¿¡ ¸ÂÀ» Áö ¸ð¸¦ "Ãß°¡" MIME Çü½Ä ¸ñ·ÏÀ» °Ë»öÇÕ´Ï´Ù. Àüü ¸ñ·ÏÀ» º¸·Á¸é http://lxr.mozilla.org/seamonkey/source/uriloader/exthandler/nsExternalHelperAppService.cpp#336 ¸¦ Âü°íÇϱ⠹ٶø´Ï´Ù. - À̰͵µ ¾ÈµÇ¸é, ÀÌ È®ÀåÀÚ¸¦ ó¸®ÇÒ ¼ö ÀÖ´Â Ç÷¯±×ÀÎÀÌ ÀÖ´Â Ç÷¯±×ÀÎ ¸ñ·ÏÀ» Á¡°ËÇÏ¿©, mimeÇü½ÄÀ» ¿äûÇÕ´Ï´Ù.
¡¡
- On BeOS, the operating system is asked for the type of the file (not quite yet, bug 217723)
- On MacOS, the type and creator code will be used to lookup the
type of the file from the OS
- a hardcoded list of extensions is checked (containing currently
13 entries, http://lxr.mozilla.org/seamonkey/source/uriloader/exthandler/nsExternalHelperAppService.cpp#299)
(This is done for speed - it is faster to find data in the hardcoded list than asking the OS or looking in preferences)
- If the extension is not listed there, it becomes interesting.
Firstly, the Operating System is asked for a MIME type.
If that fails, a user-supplied helper app is searched for by extension, and the specified MIME type will be used. (i.e. the list in Edit/Preferences/Helper Applications)
If that failed, a list of "extra" MIME types is searched for an extension match. See http://lxr.mozilla.org/seamonkey/source/uriloader/exthandler/nsExternalHelperAppService.cpp#336 for the complete list.
- If that also failed, the list of loaded plugins is checked for a plugin that can handle this extension, and is asked for the mimetype
µµ¿ì¹Ì ÇÁ·Î±×·¥
Helper Applications
´Ù¼Ò´Â ¿¬°üµÈ ¹®Á¦°¡ µµ¿ì¹Ì ÇÁ·Î±×·¥ÀÔ´Ï´Ù. ¸ðÁú¶ó°¡ ó¸®ÇÒ ¼ö ¾ø´Â Çü½ÄÀÇ uri¸¦ ºÒ·¯µéÀÏ ¶§, µµ¿ì¹Ì ÇÁ·Î±×·¥ ´ëÈâÀÌ ³ªÅ¸³ª´Â µ¥, Ç¥½ÃµÈ Á¤º¸´Â ´ÙÀ½ÀÇ ÀÚ·á¿¡¼ °¡Á®¿Â °ÍÀÔ´Ï´Ù:
A somewhat related issue are the helper applications. When loading
an uri with a type that Mozilla can not handle, a helper app dialog
shows up, and the displayed information comes from these sources:
- ÁÖ¾îÁø <È®ÀåÀÚ, mimetype>½ÖÀÇ Ã³¸®ÀÚ¸¦ OS¿¡ ¿äûÇÕ´Ï´Ù. ¿©±â¼ÀÇ È®ÀåÀÚ´Â ³»¿ë-ó¸®(Content-Dispotion) ¸Ó¸®¸» Á¤º¸°¡ ÀÖ´Â °æ¿ì À̰÷¿¡¼, ±×·¸Áö¾ÊÀº °æ¿ì¿¡´Â URL ÀÚü¿¡¼ °¡Á®¿Â °ÍÀ̶ó´Â Á¡À» ¿°µÎ¿¡ µÎ¼¼¿ä. ÀÌ·± °÷¿¡¼ µî·ÏµÈ "±âº»ÇÁ·Î±×·¥"À» °¡Á®¿À´Â °ÍÀÔ´Ï´Ù.
- uriÀÇ MIME Çü½ÄÀ» °¡Áø ¿£Æ®¸®¸¦ ã±â À§ÇØ "µ¥ÀÌŸ ÀÚ·á"(Áï µµ¿ì¹Ì ÇÁ·Î±×·¥ ¸ñ·Ï)¸¦ °Ë»öÇÕ´Ï´Ù. °á°ú°¡ ¾øÀ¸¸é, µ¥ÀÌŸ ÀڷḦ È®ÀåÀÚ¸¦ ÅëÇØ¼ °Ë»öÇÕ´Ï´Ù.(À§¿¡¼ À̾߱âÇÑ ³»¿ë-󸮿¡¼). ÀÌ °Ë»öÀ¸·Î °á°ú°¡ ³ª¿À¸é, ÇØ´çÇÏ´Â ÇÁ·Î±×·¥À¸·Î ¿±â(Open with) Çʵ忡, ±×¸®°í ÇØ´ç Çü½Ä¿¡ ´ëÇÑ ¼³¸íÀÌ ³ª¿À°Ô µË´Ï´Ù.
- À̰͵µ ½ÇÆÐÇϸé, Ãß°¡·Î ´Ù½Ã °Ë»öÇÏ°Ô µÇ¸ç, MIME Çü½ÄÀÇ È®ÀåÀÚ-¸ñ·Ï°ú ¼³¸íÀ» Á¦°øÇÏ°Ô µË´Ï´Ù.
¡¡
- Ask the OS for a handler of the given <extension, mimetype> pair. Note that the extension here comes from the Content-Disposition header if present, and from the URL itself otherwise. This is where the listed "default application" comes from.
- The "data source" (that is, the list of helper applications) is searched for an entry with the MIME type of the uri. If this fails, the data source is searched via the extension (Content-Disposition as above). If one of these lookups succeed, this is where the application in the "Open with" field comes from, and also where the description of the type comes from.
- If this also failed, the extras are searched again, and will supply the extension-list and a description of the MIME type.
