2022-08-23 09:57:42 +00:00
|
|
|
#lang racket/base
|
|
|
|
(require racket/dict
|
|
|
|
racket/match
|
|
|
|
racket/port
|
|
|
|
; libs
|
|
|
|
(prefix-in easy: net/http-easy)
|
|
|
|
; web server libs
|
|
|
|
net/url
|
|
|
|
web-server/http
|
|
|
|
(only-in web-server/dispatchers/dispatch next-dispatcher)
|
2022-10-09 10:43:21 +00:00
|
|
|
"application-globals.rkt"
|
2022-09-01 04:04:48 +00:00
|
|
|
"url-utils.rkt"
|
|
|
|
"xexpr-utils.rkt")
|
2022-08-23 09:57:42 +00:00
|
|
|
|
|
|
|
(provide
|
|
|
|
page-proxy)
|
|
|
|
|
|
|
|
(define (page-proxy req)
|
|
|
|
(match (dict-ref (url-query (request-uri req)) 'dest #f)
|
|
|
|
[(? string? dest)
|
|
|
|
(if (is-fandom-url? dest)
|
2022-10-04 08:00:33 +00:00
|
|
|
(response-handler ; catches and reports errors
|
2022-09-01 04:04:48 +00:00
|
|
|
(let ([dest-r (easy:get dest #:stream? #t)])
|
2022-10-04 08:00:33 +00:00
|
|
|
(with-handlers ([exn:fail? (λ (e) ; cleans up and re-throws
|
|
|
|
(easy:response-close! dest-r)
|
|
|
|
(raise e))])
|
|
|
|
(response/output
|
|
|
|
#:code (easy:response-status-code dest-r)
|
|
|
|
#:mime-type (easy:response-headers-ref dest-r 'content-type)
|
2022-10-09 10:43:21 +00:00
|
|
|
#:headers (build-headers always-headers)
|
2022-10-04 08:00:33 +00:00
|
|
|
(λ (out)
|
|
|
|
(copy-port (easy:response-output dest-r) out)
|
|
|
|
(easy:response-close! dest-r))))))
|
2022-08-23 09:57:42 +00:00
|
|
|
(next-dispatcher))]
|
|
|
|
[#f (next-dispatcher)]))
|