我正在制作一个Clojure Web应用程序,使用分块的HTTP响应向客户端流式传输数据。当我使用foreman本地运行时,这很好用,但当我将其部署到Heroku上时,它不能正常工作。
可以在我的Github上找到一个展示此行为的最小示例。前端(位于
当相同的代码部署到Heroku时,HTTP连接在发送第一个块后立即被服务器关闭。看来是Heroku的路由网格导致了这种断开连接发生。
也可以通过使用curl执行GET请求来查看这一点:
有人能否解释为什么会出现这种情况?Heroku的Cedar栈应该支持HTTP流。使用
失败项目的实时演示:http://arcane-headland-2284.herokuapp.com/
可以在我的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/