       (send-repl-client-page opts conn request)
       (let [file (io/file (str (:root opts) path))]
         (if (.exists file)
-          (send-and-close conn 200 (slurp file))
+          (send-and-close conn 200 (slurp file) (content-type (.getName file)))
           (send-404 conn (:path request)))))))
 
 (defn- handle-connection

      </script>
      </head>
      <body></body>
      </html>")))

(defn handle-get [opts conn request]
  (let [path (:path request)]

    404 "HTTP/1.1 404 Not Found"
    "HTTP/1.1 500 Error"))

(def content-types {".js" "text/javascript"
                    ".html" "text/html"})

(defn content-type [file-name]
  (let [idx (.lastIndexOf file-name ".")
        ext (.substring file-name idx)]
    (get content-types ext "text/html")))

(defn send-and-close
  "Use the passed connection to send a form to the browser. Send a
  proper HTTP response."
  ([conn status form]
     (send-and-close conn status form "text/html"))
  ([conn status form content-type]
     (let [utf-8-form (.getBytes form "UTF-8")
           content-length (count utf-8-form)
           headers (map #(.getBytes (str % "\r\n"))
                        [(status-line status)
                         "Server: ClojureScript REPL"
                         (str "Content-Type: "
                              content-type
                              "; charset=utf-8")
                         (str "Content-Length: " content-length)
                         ""])]
       (with-open [os (.getOutputStream conn)]
         (do (doseq [header headers]
               (.write os header 0 (count header)))
             (.write os utf-8-form 0 content-length)
             (.flush os)
             (.close conn))))))

(defn send-404 [conn path]
  (send-and-close conn 404
                  (str "<html><body>"
                       "<h2>Page not found</h2>"
                       "No page " path " found on this server."
                       "</body></html>")
                  "text/html"))

(defn send-for-eval
  "Given a form and a return value function, send the form to the
