(in-package :http) (defparameter *address* #(0 0 0 0)) (defparameter *port* 9990) (defparameter *server* nil) (defparameter *clients* nil) (defparameter *stream* nil) (defparameter *errors* nil) (defparameter *backlog* 100) (define-symbol-macro @cs (first *clients*)) (defun content-of (path &key (root "~/celwk/static") (index "/ifs.htm")) (when (string= path "/") (setf path index)) (let ((content-type (cond ((scan "js$" path) "application/javascript") ((scan "css$" path) "text/css") ((scan "html?$" path) "text/html") ((scan "favicon.ico$" path) "image/x-icon") (:otherwise "text/plain"))) (file (concat root path))) (cond ((not (probe-file file)) "HTTP/1.1 404 Not Found Content-Length: 0 Connection: closed ") (:otherwise (multiple-value-bind (data length) (read-file (concat root path)) (fmt "HTTP/1.1 200 OK~%~ Connection: keep-alive~%~ Access-Control-Allow-Origin: *~%~ When: ~A~%~ Content-Type: ~A~%~ Content-Length: ~A~% ~A" (now) content-type length data)))))) (build-memorized @content-of content-of)