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