使用Clojure在Heroku上进行HTTP流/分块响应

ruf*_*ufo 5 http clojure heroku chunked-encoding http-kit

我正在制作一个Clojure Web应用程序,该应用程序使用分块的HTTP响应将数据流式传输到客户端。当我使用本地运行它时,此方法效果很好foreman,但是当将其部署到Heroku时,它无法正常运行。

可以在我的github上找到一个展示这种行为的最小示例。前端(中的resources/index.html)执行AJAX GET请求,并在响应块到达时打印它们。服务器使用http-kit每秒向连接的客户端发送一个新块。按照设计,HTTP请求永远不会完成。

当将相同的代码部署到Heroku时,发送第一个块后,服务器将立即关闭HTTP连接。似乎是Heroku的路由网格导致了这种断开连接的发生。

这也可以通过使用curl执行GET请求来看到:

$ curl -v http://arcane-headland-2284.herokuapp.com/stream
* About to connect() to arcane-headland-2284.herokuapp.com port 80 (#0)
*   Trying 54.243.166.168...
* Adding handle: conn: 0x6c3be0
* Adding handle: send: 0
* Adding handle: recv: 0
* Curl_addHandleToPipeline: length: 1
* - Conn 0 (0x6c3be0) send_pipe: 1, recv_pipe: 0
* Connected to arcane-headland-2284.herokuapp.com (54.243.166.168) port 80 (#0)
> GET /stream HTTP/1.1
> User-Agent: curl/7.31.0
> Host: arcane-headland-2284.herokuapp.com
> Accept: */*
> 
< HTTP/1.1 200 OK
< Content-Type: text/html; charset=utf-8
< Date: Sat, 17 Aug 2013 16:57:24 GMT
* Server http-kit is not blacklisted
< Server: http-kit
< transfer-encoding: chunked
< Connection: keep-alive
< 
* transfer closed with outstanding read data remaining
* Closing connection 0
curl: (18) transfer closed with outstanding read data remaining
The time is currently Sat Aug 17 16:57:24 UTC 2013 <-- this is the first chunk
Run Code Online (Sandbox Code Playgroud)

有人可以建议为什么会这样吗?应该在Heroku的Cedar堆栈中支持HTTP流。使用正确运行代码的事实foreman表明,这是Heroku的路由网格中的某种东西,导致其中断。

失败项目的实时演示:http : //arcane-headland-2284.herokuapp.com/

ruf*_*ufo 1

这是由于http-kit 中的一个错误造成的,该错误很快就会修复。