Welcome to the CHICKEN Scheme pasting service
Spiffy "middleware" API ideas added by DerGuteMoritz on Sat Sep 17 20:44:17 2011
;;; first idea ;; this is pretty verbose, redundant and error-prone (vhost-map `(((* any) . , (with-headers-dump (with-session (lambda (continue) ...)))))) (define (with-headers-dump handler) (lambda (continue . args) (pp (headers->list (request-headers (current-request)))) (apply handler continue args))) (define (with-session handler) (lambda (continue . args) (parameterize ((current-session ...)) (apply handler continue args)))) ;;; second idea ;; this is similar to how spiffy handlers themselves work and is less ;; redundant but requires a helper procedure `wrap-handler' (vhost-map `(((* any) . , (wrap-handler with-headers-dump with-session (lambda (continue) ...))))) (define (wrap-handler . wrappers) (let* ((wrappers (reverse wrappers)) (handler (car wrappers)) (wrappers (cdr wrappers))) (fold (lambda (wrapper handler) (lambda args (wrapper (lambda () (apply handler args))))) handler wrappers))) (define (with-headers-dump continue) (pp (headers->list (request-headers (current-request)))) (continue)) (define (with-session continue) (parameterize ((current-session ...)) (continue)))