diff --git a/src/dispatcher-tree.rkt b/src/dispatcher-tree.rkt index 9e072bc..06709a6 100644 --- a/src/dispatcher-tree.rkt +++ b/src/dispatcher-tree.rkt @@ -8,7 +8,9 @@ (prefix-in sequencer: web-server/dispatchers/dispatch-sequencer) (prefix-in lift: web-server/dispatchers/dispatch-lift) (prefix-in filter: web-server/dispatchers/dispatch-filter) + web-server/private/connection-manager "config.rkt" + "static-data.rkt" "url-utils.rkt") (provide @@ -31,6 +33,24 @@ ; don't forget that I'm returning *code* - return a call to the function (datum->syntax stx `(make-dispatcher-tree ,ds))) +(define (write-bytes* out . bs) + (for ([b bs]) (write-bytes b out))) + +;; HTTP 103 Early Hints https://datatracker.ietf.org/doc/html/rfc8297 +;; a dispatcher services a request or calls next-dispatcher +(define ((early-hints:make original-dispatcher) conn req) + ;; normally this would call output-response/method to write output based on the method + ;; e.g. if it's HEAD then only output the headers + (define o (connection-o-port conn)) + (write-bytes* o + #"HTTP/1.1 103 Early Hints\r\n" + #"Link: " (string->bytes/latin-1 link-header) #"\r\n" + #"\r\n") + (flush-output o) + ;; after doing early hints, I need to run the original dispatcher to generate the real response. + ;; dispatchers do not return anything. + (original-dispatcher conn req)) + (define (make-dispatcher-tree ds) (host:make (λ (host-sym) @@ -47,7 +67,7 @@ (pathprocedure:make "/buddyfight/wiki/It_Doesn't_Work!!" (hash-ref ds 'page-it-works)) (filter:make (pregexp (format "^/~a/wiki/Category:.+$" px-wikiname)) (lift:make (hash-ref ds 'page-category))) (filter:make (pregexp (format "^/~a/wiki/File:.+$" px-wikiname)) (lift:make (hash-ref ds 'page-file))) - (filter:make (pregexp (format "^/~a/wiki/.+$" px-wikiname)) (lift:make (hash-ref ds 'page-wiki))) + (filter:make (pregexp (format "^/~a/wiki/.+$" px-wikiname)) (early-hints:make (lift:make (hash-ref ds 'page-wiki)))) (filter:make (pregexp (format "^/~a/search$" px-wikiname)) (lift:make (hash-ref ds 'page-search))) (filter:make (pregexp (format "^/~a(/(wiki(/)?)?)?$" px-wikiname)) (lift:make (hash-ref ds 'redirect-wiki-home))) (hash-ref ds 'static-dispatcher)