Media types are used to communicate the format of the content in HTTP transactions. Clients use media types in their Accept headers to indicate what formats they prefer to receive data in. Servers use media types in their Content-Type headers to tell the client what format the accompanying entity is in--i.e., whether the enclosed text is HTML that needs to be formatted, GIF or JPEG to be rendered, or PDF format that requires opening an external viewer or using a plug-in.
See Chapter 19, HTTP Headers, for more information on the Accept and Content-Type headers.
Internet media types used by HTTP closely resemble MIME types. MIME (Multipurpose Internet Mail Extension) was designed as a method for sending attachments in mail over the Internet. Like MIME, media types follow the format type/subtype. Asterisks (*) represent a wildcard--for example, the following client header means that documents of all formats are accepted:
The following client header means that all text format types are accepted, regardless of the subtype:
Servers and CGI programs are expected to examine the accept types reported by the Accept header and return data of an acceptable type when possible. Most servers determine the format of a document from its filename suffix--for example, a file ending with .htm or .html is assumed to be HTML format, so the server will send the document with a Content-Type of text/html. When calling a CGI program, servers cannot know the format of the data being returned, so the CGI program is responsible for reporting the content type itself. For that reason, every CGI program needs to include a Content-Type header such as:
The following table lists commonly-used media types along with the filename suffixes recognized by most servers. Most servers can be easily configured to recognize additional suffixes as well.
|ai, eps, ps
|t, tr, roff
|aif, aiff, aifc
|jpeg, jpg, jpe
|mpeg, mpg, mpe
|This HTML Help has been published using the chm2web software.