ObjectType directives determine the MIME type of the file to send to the client in response to a request. MIME attributes currently sent are type, encoding, and language. The MIME type is sent to the client as the value of the Content-Type header.
ObjectType directives also set the type parameter, which is used by Service directives to determine how to process the request according to what kind of content is being requested.
If there is more than one ObjectType directive in an object, all of the directives are applied in the order they appear. If a directive sets an attribute and later directives try to set that attribute to something else, the first setting is used and the subsequent ones are ignored.
The obj.conf file almost always has an ObjectType directive that calls the type-by-extension function. This function instructs the server to look in a particular file (the MIME types file) to deduce the content type from the extension of the requested resource.
The following ObjectType-class functions are described in detail in this section:
force-type sets the Content-Type header for the response to a specific type.
match-browser matches specific strings in the User-Agent string supplied by the browser, and then modifies the behavior of Sun Java System Web Server based upon the results by setting values for specified variables.
set-default-type allows you to define a default charset, content-encoding, and content-language for the response being sent back to the client.
set-variable enables you to change server settings based upon conditional information in a request, and to manipulate variables in parameter blocks by using specific commands.
shtml-hacktype requests that .htm and .html files are parsed for server-parsed HTML commands.
type-by-exp sets the Content-Type header for the response based on the requested path.
type-by-extension sets the Content-Type header for the response based on the file’s extension and the MIME types database.
Applicable in ObjectType-class directives.
The force-type function assigns a type to requests that do not already have a MIME type. This is used to specify a default object type.
Make sure that the directive that calls this function comes last in the list of ObjectType directives, so that all other ObjectType directives have a chance to set the MIME type first. If there is more than one ObjectType directive in an object, all of the directives are applied in the order they appear. If a directive sets an attribute and later directives try to set that attribute to something else, the first setting is used and the subsequent ones are ignored.
The following table describes parameters for the force-type function.
Table 4–34 force-type Parameters
Parameter |
Description |
---|---|
(Optional) Type assigned to a matching request (the Content-Type header). |
|
(Optional) Encoding assigned to a matching request (the Content-Encoding header). |
|
(Optional) Language assigned to a matching request (the Content-Language header). |
|
(Optional) Character set for the magnus-charset parameter in rq->srvhdrs. If the browser sent the Accept-Charset header or its User-Agent is Mozilla™/1.1 or newer, then append “; charset=charset” to content-type, where charset is the value of the magnus-charset parameter in rq->srvhdrs. |
|
bucket |
(Optional) Common to all obj.conf functions. |
ObjectType fn=force-type type=text/plain ObjectType fn=force-type lang=en_US |
type-by-extension, type-by-exp
Applicable in all stage directives. The match-browser SAF matches specific strings in the User-Agent string supplied by the browser, and then modifies the behavior of Sun Java System Web Server based upon the results by setting values for specified variables. See match-browser.
Applicable in ObjectType-class directives.
The set-default-type function allows you to define a default charset, content-encoding, and content-language for the response being sent back to the client.
If the charset, content-encoding, and content-language have not been set for a response, then just before the headers are sent the defaults defined by set-default-type are used. Note that by placing this function in different objects in obj.conf, you can define different defaults for different parts of the document tree.
The following table describes parameters for the set-default-type function.
Table 4–35 set-default-type Parameters
Parameter |
Description |
---|---|
(Optional) Encoding assigned to a matching request (the Content-Encoding header). |
|
(Optional) Language assigned to a matching request (the Content-Language header). |
|
(Optional) Character set for the magnus-charset parameter in rq->srvhdrs. If the browser sent the Accept-Charset header or its User-agent is Mozilla/1.1 or newer, then append “; charset=charset” to content-type, where charset is the value of the magnus-charset parameter in rq->srvhdrs. |
|
bucket |
(Optional) Common to all obj.conf functions. |
ObjectType fn="set-default-type" charset="iso_8859-1" |
Applicable in all stage directives. The set-variable SAF enables you to change server settings based upon conditional information in a request, and to manipulate variables in parameter blocks by using specific commands. See set-variable.
Applicable in ObjectType-class directives.
The shtml-hacktype function changes the Content-Type of any .htm or .html file to magnus-internal/parsed-html and returns REQ_PROCEED. This provides backward compatibility with server-side includes for files with .htm or .html extensions. The function may also check the execute bit for the file on UNIX systems. The use of this function is not recommended.
The following table describes parameters for the shtml-hacktype function.
Table 4–36 shtml-hacktype Parameters
Parameter |
Description |
---|---|
(UNIX only, optional) Tells the function to change the content-type only if the execute bit is enabled. The value of the parameter is not important; it need only be provided. You may use exec-hack=true. |
|
bucket |
(Optional) Common to all obj.conf functions. |
ObjectType fn=shtml-hacktype exec-hack=true |
Applicable in ObjectType-class directives.
The type-by-exp function matches the current path with a wildcard expression. If the two match, the type parameter information is applied to the file. This is the same as type-by-extension, except you use wildcard patterns for the files or directories specified in the URLs.
The following table describes parameters for the type-by-exp function.
Table 4–37 type-by-exp Parameters
Parameter |
Description |
---|---|
Wildcard pattern of paths for which this function is applied. |
|
(Optional) Type assigned to a matching request (the Content-Type header). |
|
(Optional) Encoding assigned to a matching request (the Content-Encoding header). |
|
(Optional) Language assigned to a matching request (the Content-Language header). |
|
(Optional) is the character set for the magnus-charset parameter in rq->srvhdrs. If the browser sent the Accept-Charset header or its User-Agent is Mozilla/1.1 or newer, then append “; charset=charset” to content-type, where charset is the value of the magnus-charset parameter in rq->srvhdrs. |
|
bucket |
(Optional) Common to all obj.conf functions. |
ObjectType fn=type-by-exp exp=*.test type=application/html |
Applicable in ObjectType-class directives.
The type-by-extension function instructs the server to look in a table of MIME type mappings to find the MIME type of the requested resource according to the extension of the requested resource. The MIME type is added to the Content-Type header sent back to the client.
The table of MIME type mappings is created by a MIME element in the server.xml file, which loads a MIME types file or list and creates the mappings. For more information about server.xml and MIME types files, see the Sun Java System Web Server 6.1 SP11 Administrator’s Configuration File Reference.
For example, the following two lines are part of a MIME types file:
type=text/html exts=htm,htmltype=text/plain exts=txt |
If the extension of the requested resource is htm or html, the type-by-extension file sets the type to text/html. If the extension is .txt, the function sets the type to text/plain.
The following table describes parameters for the type-by-extension function.
Table 4–38 type-by-extension Parameters
Parameter |
Description |
---|---|
bucket |
(Optional) Common to all obj.conf functions. |
ObjectType fn=type-by-extension |