有关 sw-http 中 APPLICATION-FINDER-FN 的详细信息

发布于 2025-01-07 11:57:23 字数 621 浏览 6 评论 0原文

我正在寻找在 Common Lisp 中进行一些同步网络编程,并且我正在收集选项。其中之一是 sw-http,一个“为阿贾克斯/彗星”。该文档似乎有点缺乏,因为我能找到的唯一一块告诉你

子类 SERVER 并将 APPLICATION-FINDER-FN 插槽设置为回调 生成您的内容。

似乎没有任何关于回调应该是什么样子的注释或示例(一些提示告诉我它应该期望一个 server 和一个 connection 作为参数,但是没有关于它应该返回或做什么的信息)。

将其设置为天真的东西

(lambda (server conn) (declare (ignore server conn)) "Hello world")

似乎没有做任何事情,所以我假设我要么需要写入某处的流,要么以更少的方式与 server/connection 交互-比完全显而易见的方式。

有什么提示吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绅士风度i 2025-01-14 11:57:23

该处理程序采用一个连接,该连接具有一个响应,其中包含一些

假设您要将内容添加到连接响应(即八位字节)中。幸运的是,定义了一些辅助方法来使这变得更容易。

你可以尝试这个(我无法编译 SW-HTTP,所以我不能):

(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)))

祝你好运!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文