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

Pierre THIERRY nowhere.man at levallois.eu.org
Sun Apr 1 14:24:11 UTC 2007


Scribit Andrei Stebakov dies 27/03/2007 hora 10:36:
> Pierre, I am not sure I understood you. Could you give some example of
> what you described?

Sure, here is a file with a complete toy example. Just load the file and
go to the following URI:

http://localhost:8888/step1

After approximately 8 seconds, your browser should show you a second
page, located at:

http://localhost:8888/step2

In the meantime, most browsers should leave the first page visible. I'm
confident this works on most mainstream browsers because the french
national railroad company uses this trick on its online store (that's
where I learned it, by the way, I seem to remember).

I successfully tested this example under SBCL 1.0.0.0 with Linux and
both Firefox and Konqueror.

Visually,
Pierre
-- 
nowhere.man at levallois.eu.org
OpenPGP 0xD9D50D8A
-------------- next part --------------
#|

Copyright (c) 2007 Pierre Thierry <nowhere.man at levallois.eu.org>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

|#



#| Load and use the needed packages |#

(asdf:oos 'asdf:load-op :hunchentoot)
(asdf:oos 'asdf:load-op :cl-who)

(use-package :hunchentoot)
(use-package :cl-who)


#| Define the two functions that output pages |#

(defun waiter-page (title finished-uri)
  "Return a web page that immediately redirects to another URI"
  (let ((refresh-content (format nil "0;URL=~a" finished-uri)))
    (with-html-output-to-string (out nil :prologue t :indent t)
      (:html
       (:head
	(:title (esc title))
	(:meta :http-equiv "refresh" :content refresh-content))
       (:body
	(:h1 (esc title))
	(:p "Wait. Loooong."))))))

(defun slow-page (message)
  "Return a web page showing a message, but only after waiting some time"
  (sleep 8)
  (with-html-output-to-string (out nil :prologue t :indent t)
    (:html
     (:head
      (:title "Message")
      (:body
       (:h1 "Message")
       (:p (esc message))
       (:hr)
       (:p "Wow. Took time!"))))))


#| Setup the server |#

(push (create-prefix-dispatcher "/step1" (lambda () (waiter-page "Testing two-steps serving" "/step2"))) *dispatch-table*)
(push (create-prefix-dispatcher "/step2" (lambda () (slow-page "It's done"))) *dispatch-table*)
(start-server :port 8888)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <https://mailman.common-lisp.net/pipermail/tbnl-devel/attachments/20070401/a2329dc7/attachment.sig>


More information about the Tbnl-devel mailing list