[plt-scheme] Module-based web servlet examples

From: Norman Gray (norman at astro.gla.ac.uk)
Date: Tue Oct 17 10:13:27 EDT 2006

Noel and Jens -- thanks for your help, here.

On 2006 Oct 17, Norman Gray wrote:

>> Can anyone point me towards examples of module-based servlets  
>> within the PLT Scheme web server?

On 2006 Oct 17 , at 12.39, Jens Axel Søgaard wrote:

> ---
> Erroneous Xexpr
>
> An Xexpr in the servlet is malformed. The exact error is
>
> Expected a string, symbol, number, comment, processing instruction,  
> or list, given #
>
> The Full Xexpr Is
>
> #

It looks like there may be something platform-dependent, here (Jens  
is clearly on Windows, I'm on OS X).

Jens described what he did with my example, which worked.  Doing  
apparently the same thing on my machine failed.  But I think I've  
isolated a problem.

The following servlet works:

(module minimal-servlet mzscheme
    (provide interface-version timeout start)
    (require (lib "servlet.ss" "web-server"))
    (define interface-version 'v1)
    (define timeout 10)

    (define (start rq)
      (define-struct wibble (foo))
      (let ((w (make-wibble "arg")))
        `(html
          (head (title "Minimal servlet"))
          (body (h1 "Minimal servlet")
                (p ,(format "~s" w))))))
)

But replacing the last item in the Xexpr by (p ,w) hangs in the way I  
described.  That is, it was the (td ,(request-uri rq)) in my original  
version that was causing the trouble.

It appears, therefore, that the code translating the Xexpr to XML  
might be a little fragile, at least on this platform (a platform  
dependency here is surely surprising...).

Jens Axel Søgaard wrote:
>
>> Jay: Is the documentation on bindings still up-to-date?
>> <http://download.plt-scheme.org/doc/352/html/web-server/web-server- 
>> Z-H-12.html#node_idx_126>
>>
>
> Nevermind, I found the new documentation here:
>
> <http://pre.plt-scheme.org/docs/html/web-server/web-server-Z- 
> H-12.html#node_sec_10.1.2>

There might still be a mismatch.  That page documents the 'request'  
structure as

     (define-struct request (method uri headers bindings host-ip  
client-ip))

But .../PLT\ Scheme\ v352/collects/web-server/request-structs.ss  
includes

     (define-struct request (method uri headers/raw bindings/raw
                                  host-ip host-port client-ip))

Ought I to be worried by the mismatch?  I think this is being  
included by servlet.ss, via servlet-structs.ss, if I'm interpreting  
the module loading semantics correctly.

All the best,

Norman


-- 
------------------------------------------------------------------------ 
----
Norman Gray  /  http://nxg.me.uk
eurovotech.org  /  University of Leicester, UK





Posted on the users mailing list.