[racket] Lazy Request Handler

From: Nathan Breit (nabreit at gmail.com)
Date: Wed Mar 21 13:44:37 EDT 2012

I'm trying to write a servlet that plugs into the existing server. Here's
an example:

#lang racket
(require web-server/servlet-env)
(require web-server/http/bindings)
(require web-server/http/response-structs)
(require web-server/http/xexpr)

(require racket/sandbox)
(define lazy-eval (make-evaluator 'lazy))

(map lazy-eval
     '(
       (require web-server/http/bindings)
       (require web-server/http/response-structs)
       (require web-server/http/xexpr)
       (require racket/promise)
       (define (lazy-handler request)
         (let ((bindings (request-bindings request)))
           (if (exists-binding? 'hi bindings)
               (response/xexpr "Hi!")
               "")))
       ))

(define (start request)
  (force ((lazy-eval 'lazy-handler)
          request)))

(serve/servlet start
               #:launch-browser? #f
               #:quit? #f
               #:listen-ip #f
               #:servlet-path ""
               #:port 8080
               #:servlet-regexp #rx"main.*"
               #:extra-files-paths
               (list (build-path (current-directory) "extraFiles")))

On Wed, Mar 21, 2012 at 6:22 AM, Matthias Felleisen <matthias at ccs.neu.edu>wrote:

>
>
> On Mar 21, 2012, at 5:18 AM, Nathan Breit wrote:
>
> > Hi,
> > I'm trying to implement a Racket web-server handler that does lazy
> evaluation. My approach so far as been to try making a evaluator/namespace
> that uses the lazy racket, then evaluate a function in it that returns a
> lazy request handler. However, I'm running into problems getting the
> handler to read the request object. My last resort will be to make a
> request serializer and pass serialized requests into the handler, but is
> there a better way?
> > Thanks,
> > -Nathan
> > ____________________
> >  Racket Users list:
> >  http://lists.racket-lang.org/users
>
>
>
> Are you trying to write a web server in Lazy or are you trying to write a
> servlet in Lazy and plug it into the existing strict server? Perhaps you
> want to post a code snippet that shows where things fail. -- Matthias
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120321/f532a0d5/attachment.html>

Posted on the users mailing list.