HTTP-Kit 流式传输和 curl

HTTP-Kit streaming and curl

我尝试了 HTTP-Kit (http://www.http-kit.org/server.html#async) 的 HTTP 流的基本示例,但是如果我 curl 到端点,我会在连接关闭后立即收到所有消息(而不是每 200 毫秒获取一次,因为它在浏览器中工作)。这是怎么回事?

我也这样试过:

    (schedule-task (* id 200) ;; send a message every 200ms
                   (send! channel
                          {:status 200
                           :headers {"Content-Type" "text/event-stream"
                                     "Connection" "keep-alive"}
                           :body (str "message from server #" id)}
                          false)) ; false => don't close after send

行为相同。

似乎是 curl 和 Streaming http 的问题。根据this post,选项的顺序很重要

此外,尝试使用 -N, --no-buffer 选项