Version 5 of Wibble help

Updated 2012-02-13 02:14:48 by AMG

AMG: This page is for questions and answers about how to use the Wibble web server. Report bugs at Wibble bugs.

Fetching backrefs...

Put your question here

JM 12Feb2012 - the file index.html.tmpl on the "image file upload, cookies, sessions" example on Wibble examples is somehow connected to the "image.script" file mentioned in step 3, how that works?

AMG: image.script serves the images; that's all it does. I'll repeat it here, annotated with copious comments:

# If there is a sessionid cookie in the header,
if {[dict exists $header cookie sessionid ""]} {
  # Link the local session variable to an element in the global session array.
  # The linked element is the one whose key is the same as the value stored in
  # the sessionid cookie.  It's quite possible that the element doesn't exist,
  # but create the link anyway.
  upvar #0 sessions([dict get $header cookie sessionid ""]) session
}

# If:
# 1. [info exists session]: there was a sessionid cookie, and there exists an
#    associated element in the global sessions array,
# 2. [dict exists $session imagetype]: the imagetype dict element exists in
#    the value stored in the session variable,
# 3. [dict exists $session imagedata]: and the imagedata dict element exists,
if {[info exists session] && [dict exists $session imagetype]
 && [dict exists $session imagedata]} {
  # Serve the image to the client.  Use the imagetype dict element as the HTTP
  # content-type, and use the imagedata dict element as the content.
  dict set response header content-type [dict get $session imagetype]
  dict set response content [dict get $session imagedata]
} else {
  # But if any of that stuff wasn't true (e.g., no session data), 404 error.
  dict set response status 404
}