#lang scheme/base
(require web-server/servlet
(planet untyped/unlib/bytes)
(planet untyped/unlib/number)
"../base.ss"
"util.ss")
(define (make-plain-response
#:code [code 200]
#:message [message "OK"]
#:seconds [seconds (current-seconds)]
#:mime-type [mime-type #"text/plain; charset=utf-8"]
#:headers [headers no-cache-http-headers]
content)
(make-response/full code message seconds (ensure-bytes mime-type) headers content))
(define (make-plain-response/incremental
#:code [code 200]
#:message [message "OK"]
#:seconds [seconds (current-seconds)]
#:mime-type [mime-type #"text/plain; charset=utf-8"]
#:headers [headers no-cache-http-headers]
generator)
(make-response/incremental code message seconds (ensure-bytes mime-type) headers generator))
(define (make-redirect-response url
#:code [code 302]
#:message [message "Moved temporarily"]
#:headers [headers no-cache-http-headers])
(make-plain-response
#:code code
#:message message
#:headers (cons (make-header #"Location" (string->bytes/utf-8 (if (string? url) url (url->string url))))
(filter (lambda (header)
(and (not (equal? (header-field header) #"Location"))
(not (equal? (header-field header) #"location"))))
headers))
(list "Redirecting you - please wait...")))
(provide/contract
[make-plain-response
(->* ((listof (or/c string? bytes?)))
(#:code natural?
#:message string?
#:seconds natural?
#:mime-type bytes?
#:headers (listof header?))
response?)]
[make-plain-response/incremental
(->* (procedure?)
(#:code natural?
#:message string?
#:seconds natural?
#:mime-type bytes?
#:headers (listof header?))
response?)]
[make-redirect-response
(->* ((or/c string? url?))
(#:code natural?
#:message string?
#:headers (listof header?))
response?)])