[plt-scheme] Request for small API change in web-server request structure

From: Danny Yoo (dyoo at hkn.eecs.berkeley.edu)
Date: Sat Nov 11 02:56:11 EST 2006

On Sat, 11 Nov 2006, Jay McCarthy wrote:

> Please send me what you're using as test scripts once they're hammered out.

Here's what I have so far, attached as "test-post-patch.ss".  I need to 
add more tests, but I also need to sleep.  *grin* I'll see if I can send 
you a few more tomorrow evening.

Hope this helps!
-------------- next part --------------
(module test-post-patch mzscheme
  (require (lib "connection-structs.ss" "web-server/private")
           (lib "timer-structs.ss" "web-server/private")
           (lib "request-structs.ss" "web-server")
           (planet "util.ss" ("schematics" "schemeunit.plt" 2))
           (planet "test.ss" ("schematics" "schemeunit.plt" 2))
           (planet "text-ui.ss" ("schematics" "schemeunit.plt" 2)))
  (require/expose (lib "request.ss" "web-server/private") (read-bindings&post-data/raw))
  ;; mock connection object for test on post body parsing
  (define (make-mock-connection&headers post-body)
    (let* ([bytes (string->bytes/utf-8 post-body)]
           [headers (list (make-header
                            (number->string (bytes-length bytes)))))]
           [ip (open-input-bytes bytes)]
           [op (open-output-bytes)])
      (values (make-connection (make-timer ip +inf.0 (lambda () (void)))
  (define (get-bindings post-data)
    (define-values (conn headers) (make-mock-connection&headers post-data))
    (call-with-values (lambda () (read-bindings&post-data/raw conn 'post #f headers))
                      (lambda (f s) f)))
  (define (get-post-data/raw post-data)
    (define-values (conn headers) (make-mock-connection&headers post-data))
    (call-with-values (lambda () (read-bindings&post-data/raw conn 'post #f headers))
                      (lambda (f s) s)))
  (define binding-parse-tests
     "tests for parsing bindings"
     (test-equal? "simple test 1"
                  (get-post-data/raw "hello world") #"hello world")
     (test-equal? "simple test 2"
                  (get-post-data/raw "hello=world") #"hello=world")
     (test-equal? "simple test 3"
                  (binding:form-value (bindings-assq #"hello" (get-bindings "hello=world")))
  (test/text-ui binding-parse-tests))

Posted on the users mailing list.