 (ns inf4375-simple-server.core
   (:gen-class)
-  (:import (java.io InputStreamReader PrintWriter BufferedReader ByteArrayOutputStream )
+  (:import (java.io InputStreamReader PrintWriter BufferedReader)
            (java.net ServerSocket))
   (:require [clojure.string :as str]
             [clojure.pprint :as pp]
             [me.raynes.fs   :as fs]))
 
 (defn consume-buffer [input]
+  "Consume a input buffer and gives it content as a list of string"
   (loop  [lines '()]
     (if (.ready input)
       (recur(concat lines (list (.readLine input))))
       (remove (fn [l] (empty? l))lines))))
 
 (defn parse-request [lines]
+  "Structure a http requests"
   (let [[request-line & headers] lines
         [method uri version] (str/split request-line #" ")]
     {:request-line

                             (assoc memo (keyword k) (str/trim v))))
                      (sorted-map) headers)}))

(defn compose [lines]
  (reduce
    (fn [res, el] (str/join (list res el "\r\n")))
    lines))

(defmulti generate-response (fn [code _] code))
(defmethod generate-response :404 [_ _]
  (let [page-content "<h1>404 Not Found</h1>"]
    (compose
      (list
        "HTTP/1.1 404 Not Found"
        "Content-Type: text/html; charset=utf-8"

        page-content))))

(defmethod generate-response :200 [_ res-as-string]
  (compose-list (list
             "HTTP/1.1 200 OK"
             "content-type: text/html; charset=utf-8"
             (format "content-length: %s" (count res-as-string))
