forked from cadence/breezewiki
Trying out HTTP 103 Early Hints
This commit is contained in:
parent
565d0a439a
commit
8a44f9176e
1 changed files with 21 additions and 1 deletions
|
@ -8,7 +8,9 @@
|
||||||
(prefix-in sequencer: web-server/dispatchers/dispatch-sequencer)
|
(prefix-in sequencer: web-server/dispatchers/dispatch-sequencer)
|
||||||
(prefix-in lift: web-server/dispatchers/dispatch-lift)
|
(prefix-in lift: web-server/dispatchers/dispatch-lift)
|
||||||
(prefix-in filter: web-server/dispatchers/dispatch-filter)
|
(prefix-in filter: web-server/dispatchers/dispatch-filter)
|
||||||
|
web-server/private/connection-manager
|
||||||
"config.rkt"
|
"config.rkt"
|
||||||
|
"static-data.rkt"
|
||||||
"url-utils.rkt")
|
"url-utils.rkt")
|
||||||
|
|
||||||
(provide
|
(provide
|
||||||
|
@ -31,6 +33,24 @@
|
||||||
; don't forget that I'm returning *code* - return a call to the function
|
; don't forget that I'm returning *code* - return a call to the function
|
||||||
(datum->syntax stx `(make-dispatcher-tree ,ds)))
|
(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)
|
(define (make-dispatcher-tree ds)
|
||||||
(host:make
|
(host:make
|
||||||
(λ (host-sym)
|
(λ (host-sym)
|
||||||
|
@ -47,7 +67,7 @@
|
||||||
(pathprocedure:make "/buddyfight/wiki/It_Doesn't_Work!!" (hash-ref ds 'page-it-works))
|
(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/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/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/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)))
|
(filter:make (pregexp (format "^/~a(/(wiki(/)?)?)?$" px-wikiname)) (lift:make (hash-ref ds 'redirect-wiki-home)))
|
||||||
(hash-ref ds 'static-dispatcher)
|
(hash-ref ds 'static-dispatcher)
|
||||||
|
|
Loading…
Reference in a new issue