Browse Source

Let users control SSE stream completion

This commit avoid merging automatically the SSE stream with
Flux.never(). Since browsers automatically reconnect when
the HTTP connection is closed, it is now the user responsability
to optionally perform a concatWith(Flux.never()) on streams that
complete in order to avoid receiving the data multiple times on
client side.

The behavior with hot streams that never complete does not change.

Issue: SPR-14578
pull/1153/head
Sebastien Deleuze 10 years ago
parent
commit
06d4bb6a1a
  1. 4
      spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageWriter.java

4
spring-web/src/main/java/org/springframework/http/codec/ServerSentEventHttpMessageWriter.java

@ -79,10 +79,6 @@ public class ServerSentEventHttpMessageWriter implements HttpMessageWriter<Objec
DataBufferFactory bufferFactory = outputMessage.bufferFactory(); DataBufferFactory bufferFactory = outputMessage.bufferFactory();
Flux<Publisher<DataBuffer>> body = encode(inputStream, bufferFactory, type); Flux<Publisher<DataBuffer>> body = encode(inputStream, bufferFactory, type);
// Keep the SSE connection open even for cold stream in order to avoid
// unexpected browser reconnection
body = body.concatWith(Flux.never());
return outputMessage.writeAndFlushWith(body); return outputMessage.writeAndFlushWith(body);
} }

Loading…
Cancel
Save