Sun Java System Web Server 7.0 Update 3 NSAPI Developer's Guide

ObjectType() Example

The example in this section demonstrates how to implement html2shtml, a custom SAF that instructs the server to treat a .html file as a .shtml file if a .shtml version of the requested file exists.

A well-behaved ObjectType function checks whether the content type is already set. If the type is set, the function returns REQ_NOACTION.

if(pblock_findval("content-type", rq->srvhdrs))
    return REQ_NOACTION;


If the content type is not set, ObjectType directive sets the content type. This example sets the content type to magnus-internal/parsed-html in the following lines:

/* Set the content-type to magnus-internal/parsed-html */
pblock_nvinsert("content-type", "magnus-internal/parsed-html",


The html2shtml function checks the requested file name. If the name ends with .html, the function searches for a file with the same base name, with the extension .shtml. If a .shtml is found, the function uses that path and informs the server that the file is parsed HTML instead of regular HTML. Note that this check requires an extra stat call for every HTML file accessed.

Installing the ObjectType() Example

To load the shared object containing your function, add the following directive in the Init section of the magnus.conf file:

Init fn=load-modules

To execute the custom SAF during the request-response process for an object, add the following code to that object in the obj.conf file:

ObjectType fn=html2shtml

The source code for this example is in otype.c in the install-dir/samples/nsapi/ directory.