Version 1 of Wibble zone handlers

Updated 2010-11-06 17:36:05 by AMG

AMG: This page collects useful and illustrative zone handlers for the Wibble web server.

Reloading the server source

AMG: Here is a reload zone handler that reloads the server source on command.

proc reload {request response} {
    set wibble::zones {}
    foreach script [dict get $request scripts] {
        uplevel #0 [list source $script]
    }
    dict set response status 200
    dict set response header content-type text/plain
    dict set response content "Server reloaded.  Have a nice day.\n"
    wibble::sendresponse $response
}
wibble::handle /reload reload scripts [list [info script]]

Interfacing with Wub domains

CMcC - 2010-06-27 23:08:49

Something like the following shim ought to interface most Wub domains to a wibble server.

You'd have to construct the Wub domain with appropriate arguments, then in the wibble::handle definition, pass an option "domain $domain"

Some Wub domains won't work, as they require capabilities that wibble doesn't provide, but many should.

Enjoy.

proc wibble::wub {request response} {
    dict with request {}
    # remap some important request fields
    dict set r -uri $uri
    dict set r -clientheaders [dict keys $request]
    set r [dict merge $r $request [Url parse $uri 1]]

    try {
        {*}$domain do $r
    } on error {r options} {
        return [nexthandler $request $response]
    }

    # remap some important result fields
    dict set response content [dict get $r -content]
    dict set response status [dict get $r -code]
    sendresponse [dict merge $response [dict remove $r [dict keys $r -*]]]
}