Next, the server needs to execute a Service directive to generate the response to send to the client. The server looks at each Service directive in turn, to find the first one that matches the type, method and query string. If a Service directive does not specify type, method, or query string, then the unspecified attribute matches anything.
If there is more than one Service directive, the server applies the first one that matches the conditions of the request, and ignores all remaining Service directives.
As with the PathCheck and ObjectType directives, if another object has been matched to the request as a result of the NameTrans step, the server considers the Service directives in the matching object before considering the ones in the default object. If the server successfully executes a Service directive in the matching object, it will not get around to executing the Service directives in the default object, since it only executes one Service directive.
For an example of how Service directives work, consider what happens when the server receives a request for the URL D:/server_name/jos.html. In this case, all directives executed by the server are in the default object.
The following NameTrans directive translates the requested URL to <Install_Root>/<Instance_Directory>/docs/jos.html:
NameTrans fn="document-root" root="<Install_Root>/<Instance_Directory>/docs"
Assume that the PathCheck directives all succeed.
The following ObjectType directive tells the server to look up the resource’s MIME type in the MIME types table:
ObjectType fn="type-by-extension"
The server finds the following entry in the MIME types table, which sets the type attribute to text/html:
type=text/html exts=htm,html
The server invokes the following Service directive. The value of the type parameter matches anything that does not begin with magnus-internal/. This directive sends the requested file, jos.html, to the client.
Service method="(GET|HEAD|POST)" type="*~magnus-internal/*" fn="send-file"" |
Here is an example that involves using another object:
The following NameTrans directive assigns the name personnel to the request.
NameTrans fn=assign-name name=personnel from=/personnel |
As a result of the name assignment, the server switches to processing the directives in the object named personnel. This object is defined as:
<Object name="personnel"> Service fn="index-simple" </Object> |
The personnel object has no PathCheck or ObjectType directives, so the server processes the PathCheck and ObjectType directives in the default object. Let’s assume that all PathCheck and ObjectType directives succeed.
When processing Service directives, the server starts by considering the Service directive in the personnel object, which is:
Service fn="index-simple"
The server executes this Service directive, which calls the index-simple function.
Since a Service directive has now been executed, the server does not process any other Service directives. (However, if the matching object had not had a Service directive that was executed, the server would continue looking at Service directives in the default object.)
There is usually a Service directive that does the default task (sends a file) if no other Service directive matches a request sent by a browser. This default directive should come last in the list of Service directives in the default object, to ensure it only gets called if no other Service directives have succeeded. The default Service directive is usually:
Service method="(GET|HEAD|POST)" type="*~magnus-internal/*" fn="send-file" |
This directive matches requests whose method is GET, HEAD, or POST, which covers nearly virtually all requests sent by browsers. The value of the type argument uses special pattern-matching characters.
The characters “*~” mean “anything that doesn’t match the following characters,” so the expression *~magnus-internal/ means “anything that doesn’t match magnus-internal/.” An asterisk by itself matches anything, so the whole expression *~magnus-internal/* matches anything that does not begin with magnus-internal/.
So if the server has not already executed a Service directive when it reaches this directive, it executes the directive so long as the request method is GET, HEAD or POST, and the value of the type attribute does not begin with magnus-internal/. The invoked function is send-file, which simply sends the contents of the requested file to the client.