[racket] Web-Server: dispatch-rules and web-cells

From: Helmut Dobretzberger (h.dobretzberger at gmx.at)
Date: Tue Nov 27 09:00:46 EST 2012


I'd like to have pretty urls in my web-application, but I ran into a problem
when using web-cells.

I use a web-cell, and I shadow the content within the response/xexpr. 
I link to a second function, which only shows the content of the web-cell.
If I generate this link using embed/url, everything is fine.
But if I use a pretty url, the content of the web-cell is lost.

I understand the reason, I think - within the send/suspend/dispatch, the
continuation is saved, so the generated link restores the continuation,
including the web-cell content.
And that doesn't happen with pretty urls, right?

But is there a way to use a pretty url, so that the content of the web-cell
is not lost? 

A running, not really useful example, which demonstrates the problem:

#lang racket

(require web-server/servlet)
(require xml)

(define my-cell (make-web-cell 0))

(define (start initial-request)
   (lambda (embed/url)
        ,(begin (web-cell-shadow my-cell 1)
                (number->string (web-cell-ref my-cell)))
        (a ([href "/foobar"]) "Foo") ;;pretty url
        (a ([href ,(embed/url start2)]) "Start")))))) ;; generated url

(define (start2 request)
   `(html ,(number->string (web-cell-ref my-cell)))))
   ;; returns 0 if called via "foobar" and 1 if called with (embed/url

(require web-server/servlet-env)

(define-values (start-dispatch simple-app-url)
   [("") start]
   [("foobar") start2]])

;; Startet das Servlet.
(serve/servlet start-dispatch
               #:port 8080
               #:listen-ip #f
               #:launch-browser? #t
               #:servlet-path "/"
               #:servlet-regexp #rx"")


Posted on the users mailing list.