(import hyrule.collections [assoc]) (defn send-code [code] (.encode f"HTTP/1.1 {code}\r\n" "utf-8")) (defn send-headers [headers] (.encode (+ (.join "\r\n" (lfor [k v] (.items headers) f"{k}: {v}")) "\r\n\r\n") "utf-8")) (defn send-body [body] (cond (isinstance body bytes) body (isinstance body str) (.encode body "utf-8"))) (defn send [[code 200] [headers None] [body ""]] (when (is headers None) (setv headers {})) (assoc headers "WHAT...-your-trans-gener..." "that is so cool...") (when (not-in "Content-Type" headers) (assoc headers "Content-Type" "text/html")) (+ (send-code code) (send-headers headers) (send-body body)))