Skip to content

Commit b4c41be

Browse files
committed
Switch to empty SSE comment events for keep-alive
Prior to this commit, the SSE handler was using a "comment" event with a single space character for keep-alive purposes because Spring Framework did not support empty comments. This has been fixed in Framework, we can now use empty comments. Closes gh-1431
1 parent 6b168c2 commit b4c41be

2 files changed

Lines changed: 4 additions & 6 deletions

File tree

spring-graphql/src/main/java/org/springframework/graphql/server/webmvc/GraphQlSseHandler.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,7 @@ private void sendNext(Map<String, Object> value) {
165165

166166
private void sendHeartbeat() {
167167
try {
168-
// Currently, comment cannot be empty:
169-
// https://github.com/spring-projects/spring-framework/issues/34608
170-
this.sseBuilder.comment(" ");
168+
this.sseBuilder.comment("");
171169
this.sseBuilder.send();
172170
}
173171
catch (IOException exception) {

spring-graphql/src/test/java/org/springframework/graphql/server/webmvc/GraphQlSseHandlerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -146,13 +146,13 @@ void shouldSendKeepAlivePings() throws Exception {
146146

147147
assertThat(response.getContentAsString())
148148
.startsWith("""
149-
:\s
149+
:
150150
151-
:\s
151+
:
152152
153153
""")
154154
.endsWith("""
155-
:\s
155+
:
156156
157157
event:complete
158158
data:

0 commit comments

Comments
 (0)