| [ Team LiB ] |
|
Standard Application Direct URLsThe server has several modules that provide Application Direct URLs. These Application Direct URLs let you control the server or examine its state from any Web browser. You can look at the implementation of these modules as examples for your own application. StatusThe /status URL is implemented in the status.tcl file. The status module implements the display of hit counts, document hits, and document misses (i.e., documents not found). The Status_Url command enables the Application Direct URLs and assigns the top-level URL for the status module. The default configuration file contains this command: Status_Url /status Table 18-8 shows the URLs implemented by the status module:
DebuggingThe /debug URL is implemented in the debug.tcl file. The debug module has several useful URLs that let you examine variable values and other internal state. It is turned on with this command in the default configuration file: Debug_Url /debug Table 18-9 lists the /debug URLs. These URLs often require parameters that you can specify directly in the URL. For example, the /debug/echo URL echoes its query parameters:
Note: The debug URL is active in the default configuration. If it makes you nervous, then delete the call to Debug_Url from the httpdthread.tcl file. The sample URL tree that is included in the distribution includes the file htdocs/hacks.html. This file has several small forms that use the /debug URLs to examine variables and source files. It may seem dangerous to have these facilities, but I reason that because my source directories are under my control, it cannot hurt to reload any source files. In general, the library scripts contain only procedure definitions and no global code that might reset state inappropriately. In practice, the ability to tune (i.e., fix bugs) in the running server has proven useful to me on many occasions. It lets you evolve your application without restarting it!
Example 18-19 shows the implementation of /debug/source. You can see that it limits the files to the main script library and to the script library associated with document templates. Example 18-19 The /debug/source Application Direct URL implementation
proc Debug/source {source} {
global Httpd Config errorInfo
set source [file tail $source]
set dirlist $Httpd(library) ;# TclHttpd implementation
lappend dirlist $Config(lib) ;# Application custom code
foreach dir $dirlist {
set file [file join $dir $source]
if {[file exists $file]} break
}
set error [catch {uplevel #0 [list source $file]} result]
set html "<title>Source $source</title>\n"
if {$error} {
append html "<H1>Error in $source</H1>\n"
append html "<pre>$result<p>$errorInfo</pre>"
} else {
append html "<H1>Reloaded $source</H1>\n"
append html "<pre>$result</pre>"
}
return $html
}
Sending EmailThe /mail URL is implemented in the mail.tcl file. The mail module implements various form handlers that email form data. Currently, it is UNIX-specific because it uses /usr/lib/sendmail to send the mail. It is turned on with this command in the default configuration file: Mail_Url /mail The Application Direct URLs shown in Table 18-10 are useful form handlers. You can specify them as the ACTION parameter in your <FORM> tags. The mail module provides two Tcl procedures that are generally useful. The MailInner procedure is the one that sends mail. It is called like this:
MailInner sendto subject from type body
The sendto and from arguments are email addresses. The type is the MIME type (e.g., text/plain or text/html) and appears in a Content-Type header. The body contains the mail message without any headers. The Mail_FormInfo procedure is designed for use in HTML+Tcl template files. It takes no arguments but instead looks in current query data for its parameters. It expects to find the same arguments as the /mail/forminfo direct URL. Using a template with Mail_FormInfo gives you more control over the result page than posting directly to /mail/forminfo, and is illustrated in Example 18-12 on page 272. |
| [ Team LiB ] |
|