33 lines
1.2 KiB
Common Lisp
33 lines
1.2 KiB
Common Lisp
(in-package #:live-chat-cgi)
|
|
|
|
(defun print-http-header ()
|
|
"Print standard HTTP headers for CGI."
|
|
(format t "Content-Type: text/html~%~%"))
|
|
|
|
(defun cgi-handler ()
|
|
"Handle CGI requests and dispatch them to the appropriate logic."
|
|
(let ((request-method (string-downcase (or (getenv "REQUEST_METHOD") ""))))
|
|
(print-http-header)
|
|
(cond
|
|
((string= request-method "get")
|
|
(let ((path (getenv "PATH_INFO")))
|
|
(cond
|
|
((string= path "/chat-messages")
|
|
(render-chat-messages))
|
|
((string= path "/")
|
|
(render-chat-ui))
|
|
(t
|
|
(format t "Not Found")))))
|
|
((string= request-method "post")
|
|
;; Read the POST data
|
|
(let ((input (read-line *standard-input*)))
|
|
(when (and input (not (string= input "")))
|
|
(let ((params (split-sequence:split-sequence #\& input)))
|
|
(dolist (param params)
|
|
(let* ((pair (split-sequence:split-sequence #\= param))
|
|
(key (first pair))
|
|
(value (second pair)))
|
|
(when (string= key "message")
|
|
(handle-post-message value))))))
|
|
(render-chat-messages))))))
|