Trying out HTTP 103 Early Hints

This commit is contained in:
Cadence Ember 2022-11-12 22:04:01 +13:00
parent 565d0a439a
commit 8a44f9176e
Signed by untrusted user: cadence
GPG key ID: BC1C2C61CF521B17

View file

@ -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)