This is a simple Tcl module to enable basic HTTP 1.1 web serving. The code is derived from Wibble but has substantial differences, so it is not Wibble but it is Wibbly.
There is no equivalent of Wibble zone handlers or Tclhttpd Domains, it just calls the single handler proc you provide for each HTTP request received. Your handler code is passed a Web OBject, an instance of the class wobbly, which encapsulates the API of the web server. The Web Object provides methods to find:
Your code then processes the request however you like and calls methods on the same Web Object to specify the response:
Wibbly can process requests concurrently, handling each connection in a separate coroutine. Within your handler you should use coroutine-aware methods such as coroutine::util for any blocking operations to avoid blocking other requests.
Wibbly writes a standard-format log of web requests processed, and a separate log with details of any errors. HTML-processing utilities like template expansion and encoding/decoding functions are carried over from Wibble.
Start a web server on port 8080 which
package require wibbly
proc myhandler wob {
set path [$wob getPath]
if {$path eq "/"} {
$wob htmlResponse "<h1>Hello World</h1>The time is [clock format now]"
} elseif {[file isfile htdocs$path]} {
$wob fileResponse htdocs$path
} else {
$wob errorResponse 404
}
}
::wibbly::serve -handler myhandler
vwait foreverThe Wibbly code is at https://chiselapp.com/user/cmacleod/repository/newsgrouper/file?name=scripts/wibbly-0.5.tm&ci=tip . Documentation is at https://chiselapp.com/user/cmacleod/repository/newsgrouper/doc/tip/www/wibbly.md .