From 911faaa0ef2a09e3d3f61be64dd405f7711b92ef Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Wed, 25 Sep 2024 12:26:34 +0100 Subject: [PATCH] extract method send-error --- main.fnl | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/main.fnl b/main.fnl index b6e1747..d2d94a5 100644 --- 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 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" })]