certifix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 911faaa0ef2a09e3d3f61be64dd405f7711b92ef
parent ad29d9e1004d1a37175211ec435b12e93f7b4115
Author: Daniel Barlow <dan@telent.net>
Date:   Wed, 25 Sep 2024 12:26:34 +0100

extract method send-error

Diffstat:
Mmain.fnl | 27++++++++++++++-------------
1 file changed, 14 insertions(+), 13 deletions(-)

diff --git a/main.fnl b/main.fnl @@ -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 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] - (doto (headers.new) - (: :append ":status" :404) - (: :append :content-type :text/plain) - (out:write_headers false)) - (out:write_chunk "not found" 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" })]