Server-Sent Events (SSE) is a simple and efficient way to send real-time updates from the server to the client over HTTP. However, SSE has limitations when used with certain HTTP features, such as content compression using gzip.

The issue you are experiencing with Jersey SSE not working with Accept-Encoding gzip is likely due to the fact that SSE is not compatible with response compression. The reason is that, for SSE to work correctly, the server must be able to send data continuously as plain text without any compression.

When the client sends a request with the "Accept-Encoding: gzip" header, it indicates that it supports gzip compression for the response. If the server tries to send SSE data with gzip compression, the client won't be able to interpret the response correctly, as it expects plain text data.

To resolve this issue, you can disable gzip compression for the SSE endpoint in your Jersey application. By preventing the response from being compressed, the SSE data will be sent as plain text, and the client should be able to handle the SSE events correctly.

Here's an example of how you can disable gzip compression for a specific endpoint in Jersey:

import; import; import; import; @Path("sse") public class SSEEndpoint { @GET @Produces(MediaType.SERVER_SENT_EVENTS) public void sseEndpoint() { // Your SSE logic here } }

By not specifying the @GZip annotation or any other response compression mechanism for the SSE endpoint, you should be able to ensure that the data is sent without compression, allowing the SSE to work correctly with the client.

Keep in mind that disabling compression for the SSE endpoint might increase the amount of data transmitted over the network, so it's essential to consider the trade-off between compression and real-time updates based on your application's requirements.

Have questions or queries?
Get in Touch