在Heroku上使用Clojure实现HTTP流式传输/分块响应

5
我正在制作一个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

有人能否解释为什么会出现这种情况?Heroku的Cedar栈应该支持HTTP流。使用foreman可以正确运行代码,这表明是Heroku路由网格中的某些原因导致它无法工作。
失败项目的实时演示:http://arcane-headland-2284.herokuapp.com/
2个回答

1

0

2
很不幸,我认为这不是问题所在 - 我每秒向客户端发送数据,但连接在55秒之前就被关闭了(实际上是在第一个块之后立即关闭,即响应的大约1秒钟)。我的日志中没有任何错误 - 如果是超时,我会期望看到H12。 - rufo

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接