7.5. Customizing the Type Checking Phase

Following the successful completion of the access control and authentication steps (if configured), Apache tries to determine the MIME type (e.g., image/gif ) and encoding type (e.g., x-gzip ) of the requested document. The types and encodings are usually determined by filename extensions. (The term "suffix" is used interchangeably with "extension" in the Apache source code and documentation.) Table 7.1 lists a few common examples.

Table 7.1. MIME Types and Encodings for Common File Extensions
MIME types
extension type
.txt text/plain
.html, .htm text/html
.gif image/gif
.jpg, .jpeg image/jpeg
.mpeg, .mpg video/mpeg
pdf application/pdf
extension encoding
.gz x-gzip
.Z x-compress

By default, Apache's type checking phase is handled by the standard mod_mime module, which combines the information stored in the server's conf/mime.types file with AddType and AddEncoding directives to map file extensions onto MIME types and encodings.

The contents of the request record's content_type field are used to set the default outgoing Content-Type header, which the client uses to decide how to render the document. However, as we've seen, content handlers can, and often do, change the content type during the later response phase.

In addition to its responsibility for choosing MIME and encoding types for the requested document, the type checking phase handler also performs the crucial task of selecting the content handler for the document. ...

Get Writing Apache Modules with Perl and C now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.