-
Notifications
You must be signed in to change notification settings - Fork 1
/
server-utils.rkt
28 lines (23 loc) · 1.01 KB
/
server-utils.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#lang racket
(require web-server/templates
web-server/http/response-structs
web-server/http/request-structs)
(provide response/default template form-value)
(define (response/default #:code [code 200]
#:message [message #"Okay"]
#:seconds [seconds (current-seconds)]
#:mime-type [mime-type TEXT/HTML-MIME-TYPE]
#:headers [headers '()]
;; #:cookies [cookies '()]
#:body [body '(#"")])
(response/full code message seconds mime-type headers body))
;; TODO: Figure out how the hell macro scoping works to get
;; "templates/" appended to the syntax rule.
(define-syntax template
(syntax-rules ()
[(_ . p)
(list (string->bytes/utf-8 (include-template . p)))]))
(define (form-value id req)
(define val (bindings-assq id (request-bindings/raw req)))
(when (binding:form? val)
(bytes->string/utf-8 (binding:form-value val))))