1

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?

7
  • 2
    Obviously, you have to write to the stream of connection. But looking at sw-http code, I wouldn't suggest using it for production, although it may be worth researching a way to develop something on top of it... Feb 22, 2012 at 7:42
  • 1
    I believe Hunchentoot is the Common Lisp web server the cool kids are using these days. Feb 22, 2012 at 23:44
  • P.S., I think I agree with @VsevolodDyomkin, this library isn't ready for prime time. Feb 23, 2012 at 0:25
  • @Samuel - Aware, but AFAIK, hucnchentoot isn't so good at Comet. Granted, that may have changed since that comment, but still.
    – Inaimathi
    Feb 23, 2012 at 0:28
  • Oh, of course, it makes sense that it wouldn't now that I think about it. Feb 23, 2012 at 0:33

1 Answer 1

1

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!

3
  • Is enqueue from a specific package, or is that a notional function that should be part of sw-http?
    – Inaimathi
    Feb 23, 2012 at 1:27
  • @Inaimathi, that should probably have been queue-push from aromyxo, and the arguments are in the opposite order. Sorry. Feb 23, 2012 at 1:36
  • I'm tentatively accepting this, but it hasn't actually worked yet (I'll play around some more tomorrow and post results). Thank you :)
    – Inaimathi
    Feb 23, 2012 at 2:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.