(.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)) (template [
]
  [(def: #export 
     (->  Response)
     (|>> 
 encoding.to-utf8 (..ok )))]

  [text Text          mime.utf-8 (<|)]
  [html html.Document mime.html  html.html]
  [css  CSS           mime.css   css.css]
  [json JSON          mime.json  json@encode]
  )