chickadee » call-with-query » call-with-dynamic-fastcgi-query

call-with-dynamic-fastcgi-query quaerendumprocedure

Start a dynamic FastCGI server where output is bound to stdout; and where a monadic function taking a query-record is called for every request.

quaerendum
A monadic function receiving a query parameter
(define (call-with-dynamic-fastcgi-query quaerendum)
  (fcgi-dynamic-server-accept-loop
    (lambda (in out err env)
      (let ((environment
              (map (match-lambda
                     ((key . value) (cons (env-string->symbol key) value)))
                   (env)))
            (cookies
              (form-urldecode
                (let ((cookies
                        (string-delete
                          char-set:whitespace
                          (env "HTTP_COOKIE" ""))))
                  (and (not (string-null? cookies)) cookies))))
            (cookies2
              (form-urldecode
                (let ((cookies
                        (string-delete
                          char-set:whitespace
                          (env "HTTP_COOKIE2" ""))))
                  (and (not (string-null? cookies)) cookies))))
            (post-data (form-urldecode (fcgi-get-post-data in env)))
            (query (form-urldecode
                     (let ((query (env "QUERY_STRING")))
                       (and (not (string-null? query)) query)))))
        (parameterize
          ((current-output-port
             (make-output-port (lambda (scribendum) (out scribendum)) void))
           (current-error-port
             (make-output-port (lambda (errandum) (err errandum)) void)))
          (quaerendum
            (make-query
              environment
              (append cookies cookies2 post-data query))))))))