title: Server Sent Event connection not staying open with Apache/Thin/Sinatra
body: <p>I'm trying to setup basic server side event ability using Apache/Thin/Sinatra. Everything works as exepcted when I run the Thin server directly. When I run the Thin server through Apache using the RackBaseURI config setting, everything still works, but the connection is not persisted. It goes through a cycle of opening, writing some data to the browser and immediately closing. Seems like an Apache configuration issue? </p>
  
  <p>I've gone through the Apache config and don't see anything that seems like it would prevent an open connection. Because I'm not sure where the error is, I don't want to post endless configuration data, so I can include more if I'm missing something...</p>
  
  <p>sinatra (1.3.4),
  thin (1.5.0),
  Apache/2.2.22 (Ubuntu),
  ruby 1.8.7</p>
  
  <p>The JavaScript...</p>
  
  <pre><code>$j(function(){
  
    console.log("Starting...");
  
    var es = new EventSource("/stream_event");
  
    es.addEventListener('message', function(e) {
      console.log(e.data);
    }, false);
  
    es.addEventListener('open', function(e) {
      console.log("Connection Open");
    }, false);
  
    es.addEventListener('error', function(e) {
      console.log("error = " + e.eventPhase)
      if (e.eventPhase == EventSource.CLOSED) {
        console.log("Connection Closed");
      }
    }, false);
  }
  </code></pre>
  
  <p>The server side sinatra/ruby..</p>
  
  <pre><code>set :server, :thin
  connections = []
  
  get '/' do
    content_type 'text/event-stream'
    stream(:keep_open) { |out| 
      connections &lt;&lt; out
      out &lt;&lt; "data: hello\n\n" 
    }
  end
  
  get '/post_message' do
    connections.each { |out| out &lt;&lt; params[:message] &lt;&lt; "\n" }
    "message sent"
  end
  </code></pre>
  
  <p>EDIT:</p>
  
  <p>And here's the output I see in the browser console ...</p>
  
  <pre><code>Connection Open
  hello
  error = 2
  Connection Closed
  Connection Open
  hello
  error = 2
  Connection Closed 
  Connection Open
  hello
  error = 2
  Connection Closed 
  Connection Open
  hello
  error = 2
  Connection Closed 
  Connection Open
  hello
  error = 2
  Connection Closed  
  </code></pre>