From ad29d9e1004d1a37175211ec435b12e93f7b4115 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Wed, 25 Sep 2024 12:23:49 +0100 Subject: [PATCH] extract method make-headers --- main.fnl | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/main.fnl b/main.fnl index 3ed6cc7..b6e1747 100644 --- a/main.fnl +++ b/main.fnl @@ -46,14 +46,18 @@ (: :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)] - (doto (headers.new) - (: :append ":status" :200) - (: :append :content-type :text/plain) - (out:write_headers false)) + (let [body (out:get_body_as_string) + h (make-headers 200 { :content-type "text/plain" })] + (out:write_headers h false) (let [req (csr.new body)] - (print :subject (req:getSubject)) (out:write_chunk (new-crt req) true)))) (fn on-stream [sv out]