title: HTTP streaming / chunked responses on Heroku with clojure
body: <p>I'm making a clojure web app that streams data to clients using chunked HTTP responses. This works great when I run it locally using <code>foreman</code>, but doesn't work properly when I deploy it to Heroku.</p>
  
  <p>A minimal example exhibiting this behaviour can be found <a href="https://github.com/rufoa/heroku-problem-test-case" rel="noreferrer">on my github here</a>. The frontend (in <code>resources/index.html</code>) performs an AJAX GET request and prints the response chunks as they arrive. The server uses http-kit to send a new chunk to connected clients every second. By design, the HTTP request never completes.</p>
  
  <p>When the same code is deployed to Heroku, the HTTP connection is closed by the server immediately after the first chunk is sent. It seems to be Heroku's routing mesh which is causing this disconnection to occur.</p>
  
  <p>This can also be seen by performing the GET request using curl:</p>
  
  <pre><code>$ 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)
  &gt; GET /stream HTTP/1.1
  &gt; User-Agent: curl/7.31.0
  &gt; Host: arcane-headland-2284.herokuapp.com
  &gt; Accept: */*
  &gt; 
  &lt; HTTP/1.1 200 OK
  &lt; Content-Type: text/html; charset=utf-8
  &lt; Date: Sat, 17 Aug 2013 16:57:24 GMT
  * Server http-kit is not blacklisted
  &lt; Server: http-kit
  &lt; transfer-encoding: chunked
  &lt; Connection: keep-alive
  &lt; 
  * 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 &lt;-- this is the first chunk
  </code></pre>
  
  <p>Can anybody suggest why this is happening? HTTP streaming is supposed to be supported in Heroku's Cedar stack. The fact the code runs correctly using <code>foreman</code> suggests it is something in Heroku's routing mesh causing it to break.</p>
  
  <p>Live demo of the failing project: <a href="http://arcane-headland-2284.herokuapp.com/" rel="noreferrer">http://arcane-headland-2284.herokuapp.com/</a></p>