blob: bac0fcaaa70a3ab61f632a5bd6cb0254b4180855 (
plain)
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
(.module:
[lux (#- static)
[control
[concurrency
["." promise]
["." frp ("#;." monad)]]]
[data
["." text
format
["." encoding]]
[format
["." html]
["." css (#+ CSS)]
["." context]
["." json (#+ JSON) ("#;." codec)]]]
["." io]
[world
["." binary (#+ Binary)]]]
["." // (#+ Status Body Response Server)
["." status]
["." mime (#+ MIME)]
["." header]
[// (#+ URL)]])
(def: #export (static response)
(-> Response Server)
(function (_ request)
(promise.resolved response)))
(def: #export empty
(-> Status Response)
(let [body (frp;wrap (encoding.to-utf8 ""))]
(function (_ status)
[status
{#//.headers (|> context.empty
(header.content-length 0)
(header.content-type mime.utf-8))
#//.body body}])))
(def: #export (temporary-redirect to)
(-> URL Response)
(let [[status message] (..empty status.temporary-redirect)]
[status (update@ #//.headers (header.location to) message)]))
(def: #export not-found
Response
(..empty status.not-found))
(def: #export (content status type data)
(-> Status MIME Binary Response)
[status
{#//.headers (|> context.empty
(header.content-length (binary.size data))
(header.content-type type))
#//.body (frp;wrap data)}])
(def: #export bad-request
(-> Text Response)
(|>> encoding.to-utf8 (content status.bad-request mime.utf-8)))
(def: #export ok
(-> MIME Binary Response)
(content status.ok))
(do-template [<name> <type> <mime> <pre>]
[(def: #export <name>
(-> <type> Response)
(|>> <pre> encoding.to-utf8 (..ok <mime>)))]
[text Text mime.utf-8 (<|)]
[html html.Document mime.html html.html]
[css CSS mime.css css.css]
[json JSON mime.json json/encode]
)
|