I'm looking to do some synchronous web-programming in Common Lisp, and I'm rounding up options. One of them is sw-http
, an "HTTP server tailored for AJAX/Comet". The documentation seems to be a bit lacking because the only piece I could find tells you to
Sub-class SERVER and set the APPLICATION-FINDER-FN slot to a callback that generates your content.
There doesn't seem to be any notes or examples about what that callback should look like (some prodding told me that it should expect a server
and a connection
as arguments, but nothing about what it should return or do).
setting it to something naive like
(lambda (server conn) (declare (ignore server conn)) "Hello world")
doesn't seem to do anything, so I assume I either need to write to a stream somewhere or interact with the server
/connection
in some less-than-perfectly-obvious way.
Any hints?
The handler takes a connection
which has a response
which has some chunks
.
Presumably you're to add your content to the chunks
(which are octets
) of the response
of the connection
. Luckily there are some helper methods defined to make this easier.
You might try this (I couldn't get SW-HTTP to compile so I can't):
(defun hello (server connection)
(let*((response (cn-response connection))
(chunks (rs-chunks response)))
(queue-push chunks
(mk-response-status-code 200)
(queue-push chunks
(mk-response-message-body "Hello cruel world"))))
(defclass my-server (server)
((application-finder-fn :initform #'hello)))
Good luck!