Previous     Contents     Index     Next     
iPlanet Web Server, FastTrack Edition NSAPI Programmer's Guide



Appendix C   MIME Types


This appendix discusses the MIME types file. The sections are:



Introduction

The MIME types file in the config directory contains mappings between MIME (Multipurpose Internet Mail Extensions) types and file extensions. For example, the MIME types file maps the extensions .html and .htm extension to the type text/html:

type=text/html exts=htm,html

When the iPlanet Web Server receives a request for a resource from a client, it uses the MIME type mappings to determine what kind of resource is being requested.

MIME types can have three attributes: language (lang), encoding (enc), and content-type (type). The most commonly used attribute is type. The server frequently considers the type when deciding how to generate the response to the client. (The enc and lang attributes are rarely used).

By default, the MIME types file is called mime.types. You should not change the name of this file unless you have a particular reason for doing so -- everyone expects it to be called mime.types.



Loading the MIME Types File



When the server is initialized, an Init directive in obj.conf invokes the load-mime-types directive to load the MIME types file:

Init fn="load-types" mime-types="mime.types"

After loading the MIME types file, the server uses it to create a table of mappings between file extensions and MIME types.

If you make changes to the MIME types file, you will need to restart the server before the changes take effect. The server loads the MIME types file during the initialization step, so it does not notice any changes in the MIME types file until the next time it is initialized.



Determining the MIME Type



During the ObjectType step in the request handling process, the server determines the MIME type attributes of the resource requested by the client. Several different server application functions (SAFs) can be used to determine the MIME type, but the most commonly used one is type-by-extension. This function tells the server to look up the MIME type according to the requested resource's file extension in the MIME types table.

The directive in obj.conf that tells the server to look up the MIME type according to the extension is:

ObjectType fn=type-by-extension

If the server uses a different SAF, such as force-type, to determine the type, then the MIME types table is not used for that particular request.

For more details of the ObjectType step, see Chapter 2 "Syntax and Use of obj.conf."



How the Type Affects the Response



The server considers the value of the type attribute when deciding which Service directive in obj.conf to use to generate the response to the client.

By default, if the type does not start with magnus-internal/, the server just sends the requested file to the client. The directive in obj.conf that contains this instruction is:

Service method=(GET|HEAD|POST) type=*~magnus-internal/* fn=send-file

Note here the use of the special characters *~ to mean "does not match." See Appendix D "Wildcard Patterns" for details of special characters.

By convention, all values of type that require the server to do something other than just send the requested resource to the client start with magnus-internal/.

For example, if the requested resource's file extension is .map, the type is mapped to magnus-internal/imagemap. If the extension is .cgi, .exe, or .bat, the type is set to magnus-internal/cgi:


type=magnus-internal/imagemap       exts=map
type=magnus-internal/cgi            exts=cgi,exe,bat


If the type starts with magnus-internal/, the server executes whichever Service directive in obj.conf matches the specified type. For example, if the type is magnus-internal/imagemap, the server uses the imagemap function to generate the response to the client, as indicated by the following directive:

Service method=(GET|HEAD) type=magnus-internal/imagemap fn=imagemap

If the type is magnus-internal/servlet, the server uses the NSServletService function to generate the response to the client, as indicated by the following directive:

Service type="magnus-internal/servlet" fn="NSServletService"



What Does the Client Do with the MIME Type?



The Service function generates the data and sends it to the client that made the request. When the server sends the data to the client, it also sends headers. These headers include whichever MIME type attributes are known (which is usually type).

When the client receives the data, it uses the MIME type to decide what to do with the data. For browser clients, the usual thing is to display the data in the browser window.

If the requested resource cannot be displayed in a browser but needs to be handled by another application, its type starts with application/, for example application/octet-stream (for .bin file extensions ) or application/x-maker (for .fm file extensions). The client has its own set of user-editable mappings that tells it which application to use to handle which types of data.

For example, if the type is application/x-maker, the client usually handles it by opening Adobe FrameMaker to display the file.



Syntax of the MIME Types File



The first line in the MIME types file identifies the file format and must read:

#--Netscape Communications Corporation MIME Information

Other non-comment lines have the following format:

type=type/subtype exts=[file extensions] icon=icon

  • type/subtype is the type and subtype.

  • exts are the file extensions associated with this type.

  • icon is the name of the icon the browser displays. Netscape Navigator keeps these images internally. If you use a browser that doesn't have these icons, the server delivers them.



Sample MIME Types File

Here is an example of a MIME types file:


#--Netscape Communications Corporation MIME Information
# Do not delete the above line. It is used to identify the file type.
type=application/octet-stream      exts=bin,exe
type=application/oda               exts=oda
type=application/pdf               exts=pdf
type=application/postscript        exts=ai,eps,ps
type=application/rtf               exts=rtf
type=application/x-mif             exts=mif,fm
type=application/x-gtar            exts=gtar
type=application/x-shar            exts=shar
type=application/x-tar             exts=tar
type=application/mac-binhex40      exts=hqx

type=audio/basic                   exts=au,snd
type=audio/x-aiff                  exts=aif,aiff,aifc
type=audio/x-wav                   exts=wav

type=image/gif                     exts=gif
type=image/ief                     exts=ief
type=image/jpeg                    exts=jpeg,jpg,jpe
type=image/tiff                    exts=tiff,tif
type=image/x-rgb                   exts=rgb
type=image/x-xbitmap               exts=xbm
type=image/x-xpixmap               exts=xpm
type=image/x-xwindowdump           exts=xwd

type=text/html                     exts=htm,html
type=text/plain                    exts=txt
type=text/richtext                 exts=rtx
type=text/tab-separated-values     exts=tsv
type=text/x-setext                 exts=etx

type=video/mpeg                    exts=mpeg,mpg,mpe
type=video/quicktime               exts=qt,mov
type=video/x-msvideo               exts=avi

enc=x-gzip                         exts=gz
enc=x-compress                     exts=z
enc=x-uuencode                     exts=uu,uue

type=magnus-internal/imagemap      exts=map
type=magnus-internal/parsed-html   exts=shtml
type=magnus-internal/cgi           exts=cgi,exe,bat
type=magnus-internal/jsp           exts=jsp


Previous     Contents     Index     Next     
Copyright © 2000 Sun Microsystems, Inc. Some preexisting portions Copyright © 2000 Netscape Communications Corp. All rights reserved.

Last Updated July 13, 2000