[hunchentoot-devel] Displaying partial output from the handler?

Tobia tobia.conforto at linux.it
Mon Mar 26 19:51:26 UTC 2007


Andrei Stebakov wrote:
> I was wondering if it's possible to create a handler which can output
> some message to the user browser and then continue with it's own
> lengthy operation so that a user could see some output?

Yes it's possible, but you cannot use the "return value as document"
paradigm anymore, you need to write to the stream directly.  Which means
you might have some trouble with HTML abstraction tools such as CL-WHO.

This works for me:

(define-easy-handler (test :uri "/") ()
  (let ((*standard-output* (send-headers)))
    (format t "<html><head><title>Progressive output</title></head><body>")
    (dolist (s '("Respect" "to" "the" "man" "in" "the" "icecream" "van!"))
      (format t "~A<br/>" s)
      (force-output)
      (sleep 1))
    (format t "<p>Over and out</p></body></html>")))

Although, if the operation is very lengthy (say, more than a minute) you
should consider an anyncronous approach: a separate working thread plus
client-side page refreshes (or AJAX or an iframe) for status polling.


Tobia



More information about the Tbnl-devel mailing list