notes example: add logging

This commit is contained in:
Michiel Borkent 2020-03-29 14:16:12 +02:00
parent 22ea488666
commit 61939f88c9

View file

@ -109,36 +109,41 @@
(loop [] (loop []
(let [client-socket (.accept server-socket)] (let [client-socket (.accept server-socket)]
(future (future
(with-open [conn client-socket] (try
(let [out (io/writer (.getOutputStream conn)) (/ 1 0)
is (.getInputStream conn) (with-open [conn client-socket]
in (io/reader is) (let [out (io/writer (.getOutputStream conn))
[_req & headers :as response] is (.getInputStream conn)
(loop [headers []] in (io/reader is)
(let [line (.readLine in)] [_req & headers :as response]
(if (str/blank? line) (loop [headers []]
headers (let [line (.readLine in)]
(recur (conj headers line))))) (if (str/blank? line)
session-id (get-session-id headers) headers
form-data (let [sb (StringBuilder.)] (recur (conj headers line)))))
(loop [] session-id (get-session-id headers)
(when (.ready in) form-data (let [sb (StringBuilder.)]
(.append sb (char (.read in))) (loop []
(recur))) (when (.ready in)
(-> (str sb) (.append sb (char (.read in)))
(java.net.URLDecoder/decode))) (recur)))
_ (when debug? (println (str/join "\n" response))) (-> (str sb)
_ (when-not (str/blank? form-data) (java.net.URLDecoder/decode)))
(when debug? (println form-data)) _ (when debug? (println (str/join "\n" response)))
(let [note (str/replace form-data "note=" "")] _ (when-not (str/blank? form-data)
(write-note! note))) (when debug? (println form-data))
_ (when debug? (println))] (let [note (str/replace form-data "note=" "")]
(cond (write-note! note)))
;; if we didn't see this session before, we want the user to re-authenticate _ (when debug? (println))]
(not (contains? @known-sessions session-id)) (cond
(let [uuid (new-session!)] ;; if we didn't see this session before, we want the user to re-authenticate
(basic-auth-response out uuid)) (not (contains? @known-sessions session-id))
(not (authenticate! session-id headers)) (let [uuid (new-session!)]
(basic-auth-response out session-id) (basic-auth-response out uuid))
:else (home-response out session-id)))))) (not (authenticate! session-id headers))
(basic-auth-response out session-id)
:else (home-response out session-id))))
(catch Throwable t
(binding [*err* *out*]
(println t))))))
(recur))) (recur)))