Toadhttpd

Content
Login

Content

Content

Producing content for toadhttpd can be accomplished in a few ways.

Template Files

If you are generating a simple system that just needs a few server side tweaks, toadhttpd supports the tclhttpd style template files.

Instead of naming a file .html, name it .tml. Before delivery, the file will be read into the server, and Tcl will use subst to substitute any command calls and perform variable substitutions. The result of that is sent as the final output.

Unlike tclhttpd (which executes the script in the virtual host interpreter), toadhttpd executes the command with the object that was created to handle the request. So your template can invoke that object's methods:

[my html_header {Hello World!}]
Your Server is running.
<p>
The page your asked for was [my http_info get REQUEST_URI]. Despite appearences, that file is actually on the server as $local_file
<p>
The time is now [clock format [clock seconds]].
<p>
Have a nice day.
[my html_footer]

Simple Custom Reply Object

For more complex projects, you can create a class to manage requests, and tell the server to invoke an object of that class when replying.
tool::define myproject::reply.time {
   method content {} {
     set hour [clock format [clock seconds] -format %H]
     if {$hour > 20 || $hour < 5} {
       my content_nightowl
     } elseif {$hour >=5 && $hour < 12} {
       my content_morning
     } elseif {$hour >=12 && $hour < 5} {
       my content_afternoon
     } else {
       my content_evening
     }
   }

   method content_nightowl {} {
     my puts [my html_headers {Good god it's late}]
     # Content tailored for late, late night
     my puts [my html_footer]
   }
   method content_morning {} {
     my puts [my html_headers {Good morning!}]
     # Content tailored for in the morning
     my puts [my html_footer]
   }
   method content_afternoon {} {
     my puts [my html_headers {Good afternoon!}]
     # Content tailored for the afternoon
     my puts [my html_footer]
   }
   method content_evening {} {
     my puts [my html_headers {Good evening!}]
     # Content tailored for the evening
     my puts [my html_footer]
   }

}

Complex Custom Reply Object

For some content, you need to control how the page is dispatched. Fortuntely, that isn't too hard to do either. You just override a different method.

Coming Soon

tool::define myproject::reply.secure {
  method dispatch args {} {}
}