Welcome to the CHICKEN Scheme pasting service

super simple rack clone in scheme pasted by certainty on Fri Apr 6 20:51:23 2012

(define (test-binding)
  (values
   (lambda (proc)
     (proc "This is my input"))
   (lambda (code headers text)
     (printf "code: ~A headers: ~A text: ~A~%" code headers text))))


(define (sackup application #!key (server-binding test-binding) (port 8080))
  (receive (listener responder) (server-binding port)
    (listener
     (lambda (request)
       (application request responder)))))

(define ((add-middleware middleware application) request respond)
  (middleware request respond application))


;;;;; First test ;;;;;;;;;;;;;;;;;;;

(define (my-app request respond)
  (respond 200 '((content-type . "text/plain")) (string-downcase request)))

;; middleware altering the request
(define (modify-request request respond next)
  (next "other request" respond))

;; middleware altering the response
(define (modify-response request respond next)
  (next request (lambda (code headers body)
                  (respond 500 headers body))))

(sackup (add-middleware modify-response (add-middleware modify-request my-app)))

dead simple spiffy binding for sack added by certainty on Fri Apr 6 21:38:11 2012

(define ((sack-spiffy-handler handler not-found) _)
  ;;current-request would have to be normalized to a sack-request or
  ;;sth. 
  (handler (current-request)))

(define ((sack-spiffy-listener port) handler)
  (handle-not-found
   (let ((old-not-found (handle-not-found)))
     (sack-spiffy-handler handler old-not-found)))
  (start-server port: port))

(define (sack-spiffy-responder code headers body)
  (send-response code: code body: body header: headers))

(define (sack-spiffy-binding port)
  (values (sack-spiffy-listener port) sack-spiffy-responder))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
Which procedure can be used to check whether its argument is a procedure?
Visually impaired? Let me spell it for you (wav file) download WAV