extract method send-error

This commit is contained in:
Daniel Barlow 2024-09-25 12:26:34 +01:00
parent ad29d9e100
commit 911faaa0ef
1 changed files with 14 additions and 13 deletions

View File

@ -20,13 +20,21 @@
(f:read 20))]
(string->bignum bytes)))
(fn make-headers [status attributes]
(let [h (headers.new)]
(h:append ":status" (tostring status))
(each [k v (pairs attributes)]
(h:append k v))
h))
(fn not-found [out]
(doto (headers.new)
(: :append ":status" :404)
(: :append :content-type :text/plain)
(out:write_headers false))
(out:write_chunk "not found" true))
(fn send-error [out code text]
(out:write_headers
(make-headers code
{ :content-type "text/plain" })
false)
(out:write_chunk text true))
(fn not-found [out] (send-error out 404 "not found"))
(fn slurp [filename]
(with-open [f (io.open filename "r")] (f:read "*a")))
@ -46,13 +54,6 @@
(: :sign ca-key))]
(crt:toPEM)))
(fn make-headers [status attributes]
(let [h (headers.new)]
(h:append ":status" (tostring status))
(each [k v (pairs attributes)]
(h:append k v))
h))
(fn handle-sign-csr [out]
(let [body (out:get_body_as_string)
h (make-headers 200 { :content-type "text/plain" })]