The WebServer module exports an interface to a simple multi-threaded web server. The Start function allows the programmer to start the web server on a specific port on the host machine where WebL is running. After starting the web server, HTML and other files will be served from the fileroot directory indicated when the server was started. The programmer may publish WebL functions to be executed when specific URL paths are requested.
For example, the following program starts the web server on port 90, and publishes a function called Echo that returns an HTML page. Afterwards, its goes to sleep while requests are serviced. If a request for the URL /bin/echo is received by the server, the Echo function is invoked.
WebServer_Start("c:\\InetPub\\wwwroot", 90);
res.result = "<html><body>Hello!</body></html>";
WebServer_Publish("/bin/echo", Echo);
Functions may be published under any (case-sensitive) name. The web server will first consult the list of exported functions when a request is received, by comparing the path of the URL requested to each of the given names of the published functions. Should no published name match the URL path requested, the web server attempts to serve a file in the directory rooted by fileroot.
The formal arguments req and res represent respectively the request the web server received and the response the web server has to return. The idea is that the invoked function looks at the object req to figure out what to do, and modifies the object res to tell the server what to do (i.e. what data to return, etc.). For example, given the following request to the web server (running on a machine called ck.pa.dec.com):
http://ck.pa.dec.com:90/bin/echo?x=3&y=abc+def
the Echo function could be invoked with the following req object:
uri = "/bin/echo?x=3&y=abc+def",
param = [. y ="abc def", x = "3" .],
"Accept-Charset" = "iso-8859-1,*,utf-8",
"User-Agent" = "Mozilla/4.04[en] (WinNT; I)",
Accept = "image/gif, image/x-xbitmap,
image/jpeg, image/pjpeg, image/png, */*",
Date = "Thu May 14 15:59:01 PDT 1998",
The invoked function can now look at the fields of req to determine how to handle the request, and modify the fields of res to indicate the result to be returned (note that many of the fields are filled in to sensible values when the function is invoked). The meaning of the individual fields of the request and response object are listed in See Fields of the Request Object and See Fields of the Response Object respectively (note that all fields except statuscode are of value type string or object). The most commonly used field is param, which indicates the request parameters received.
|
Integer status code to be returned. The semantics of the codes are listed in the HTTP specification. |
|