3.3. Request Handling

The ComPactHTTPd understands several special HTTP requests which will initiate the execution of external programs, the setting of variables inside a session or context environment, the creation of new contexts for packages, projects and pools, etc. It also has an embedded interpreter for the ExHTML script language, which is used to dynamically generate parts of HTML documents. A complete description of the ExHTML language can be found in Chapter 13, a description of all possible requests in Chapter 15. We will just have a short look now.

If the server encounters an URL that just contains a document path, it will locate the requested page and send it to the browser as every other HTTP server does. If, however, the URL begins with a special path prefix like Load, Execute, Show, Edit, NewSession, LoadPkgContext, etc., it will behave quiet differently. First, it will treat the document to be sent as a dynamic ExHTML document and pass it through its embedded ExHTML interpreter. Second, it will initiate special actions that are required by the command, like spawning an external process to execute some program, or create new sessions or contexts internally.

Let's have a look at some example URLs:

(1) http://localhost:7777/

(2) http://localhost:7777/LoadDirContext?Page=config/index.htm&Session=Session1&..
         Context=/home/wagner/work/prjm/compact&NewContext=/home/wagner

(3) http://localhost:7777/LoadPkgContext?Page=package/index.htm&..
         Prefix=/home/wagner/work/m3libs&Package=langutils&..
         Session=Session1&Context=/home/wagner/work/prjm/compact

(4) http://localhost:7777/Execute?Session=Session1&..
         Context=/home/wagner/work/m3libs/langutils&Page=misc/ExecuteMS.htm&..
         Action=VCAnnotate

(5) http://localhost:7777/Terminate?Page=quit/index.htm&Session=Session0
       
All of these requests assume that the ComPactHTTPd is running on localhost and listening to port 7777.

Request (1) instructs the server to load the home page, pass it through the ExHTML interpreter, and send it to the browser. The home page is the only page that is treated as a dynamic page by default. The filename of the home page may be specified in the compactrc resource; otherwise it is index.htm.

Request (2) locates the context /home/wagner and ensures it is a directory context, if it exists, otherwise it creates this directory context on the fly. It then reads the dynamic page config/index.htm, passes it through the ExHTML interpreter, send sends the result back to the browser.

Request (3) changes the environment to the package context /home/wagner/work/m3libs/langutils, if it exists, else a new package context is created for this directory. Then the package management start page package/index.htm is loaded, the ExHTML content dynamically expanded, and sent to the browser.

Request (4) executes the action VCAnnotate within the context /home/wagner/work/m3libs/langutils. The page misc/ExecuteMS.htm is dynmically expanded (and part of it will be replaced by the output of the executed command) and sent back to the browser. The name VCAnnotate is used as an index into the HTTPdActions file, which contains action definitions for external programs executed by the server. A complete description of the file can be found in Chapter 14.

Request (5) terminates session 0 of the server (which will usually also terminate the server itself since a default session is needed), and sends back the page quit/index.htm.