title: Jersey Server Sent Events not working with Accept-Encoding gzip
body: <p>I am using Jersey 2.17 for SSE - I have the demo working per the docs: <a href="https://jersey.java.net/documentation/latest/sse.html" rel="nofollow">https://jersey.java.net/documentation/latest/sse.html</a>. </p>
  
  <p>In my tests, it works fine with simple curl requests (curl --verbose "localhost:9000/api/broadcast"), but if I add  <code>-H 'Accept-Encoding: gzip, deflate'</code> (to replicate my javascript code) it doesn't work (eventually times out with 'transfer closed with outstanding read data remaining'). I'm guessing that jersey says its GZIPed the response, but really it hasn't.</p>
  
  <p>My real problem is that the AngularJS javascript code always adds this <strong>Accept-Encoding...</strong> header. </p>
  
  <p><strong>I'm looking for a solution that will either</strong></p>
  
  <ol>
  <li>Prevent Accept-Encoding: gzip, deflate' from being added as Request Header when initialising the EventSource() object</li>
  <li>Setup Jersey to correctly handle/gzip the events sent to the client.</li>
  </ol>
  
  <p><strong>Update</strong> - I've noticed that if I close the <a href="https://jersey.java.net/apidocs/2.17/jersey/org/glassfish/jersey/media/sse/EventOutput.html" rel="nofollow">EventOutput</a> object in Java code that my events are all sent.</p>
  
  <p>This is the console output when using curl: </p>
  
  <pre><code>curl --verbose "localhost:9000/api/broadcast"  -H 'Accept-Encoding: gzip, deflate'
  
  * Hostname was NOT found in DNS cache
  *   Trying ::1...
  * connect to ::1 port 9000 failed: Connection refused
  *   Trying 127.0.0.1...
  * Connected to localhost (127.0.0.1) port 9000 (#0)
  &gt; GET /api/broadcast HTTP/1.1
  &gt; User-Agent: curl/7.37.1
  &gt; Host: localhost:9000
  &gt; Accept: */*
  &gt; Accept-Encoding: deflate, gzip
  &gt; 
  &lt; HTTP/1.1 200 OK
  * Server Apache-Coyote/1.1 is not blacklisted
  &lt; server: Apache-Coyote/1.1
  &lt; vary: Accept-Encoding
  &lt; content-encoding: deflate
  &lt; content-type: text/event-stream
  &lt; transfer-encoding: chunked
  &lt; date: Tue, 07 Apr 2015 20:35:42 GMT
  &lt; connection: close
  &lt; 
  * transfer closed with outstanding read data remaining
  * Closing connection 0
  curl: (18) transfer closed with outstanding read data remaining
  </code></pre>
  
  <p>For reference, my js code in my AngularJS app is:</p>
  
  <pre><code>    $scope.sseSource = new EventSource('/api/ptt/1/status');
      console.log( $scope.sseSource);
      $scope.sseSource.onerror = function (event) {
          console.log("onerror");
      }
      $scope.sseSource.onopen = function (event) {
          console.log("onopen");
      }
      $scope.sseSource.onmessage = function (event) {
          console.log("onmessage");
      }
  </code></pre>