~rwv/dezhemini#4: 
implement wrappers

A wrapper will wrap the global handler to do pre or post processing. Multiple wrappers can be applied. Use cases: templating, logging, adding environment variables for underlying handlers/scripts.

Here's an example that censors the use of "http" in gemtext by replacing it with "that-other-protocol":

(define (wrap handler)
  (lambda (req)
    (call-with-values
     (lambda () (handler req))
     (case-lambda
       [(status meta body)
        (if (and (= 20 status)
                 (eq? "text/gemini" meta))
            (values status meta
                    (string-replace
                     (if (string? body)
                         body
                         (read-string 65536 body))
                     "http" "that-other-protocol"))
            (values status meta body))]
       [res
        (apply values res)]))))
Status
RESOLVED FIXED
Submitter
~rwv
Assigned to
Submitted
3 years ago
Updated
1 year, 1 month ago
Labels
No labels applied.