Source
(defun serve-file (filename request response)
(with-input-from-file (file filename :element-type 'character)
(setf (get-header response "Status") "200 OK"
(get-header response "Content-Type") (switch ((pathname-type filename) :test #'string=)
("html" "text/html")
("css" "text/css")
(t "text/plain")))
(loop
with buffer = (make-array 8192 :element-type 'character)
for end-pos = (read-sequence buffer file)
until (zerop end-pos) do
(write-sequence buffer (content-stream response) :end end-pos)))
(shutdown request)
(shutdown response))Source Context