File tree Expand file tree Collapse file tree 2 files changed +22
-3
lines changed
main/java/org/springframework/web/servlet/function
test/java/org/springframework/web/servlet/function Expand file tree Collapse file tree 2 files changed +22
-3
lines changed Original file line number Diff line number Diff line change 11/*
2- * Copyright 2002-2024 the original author or authors.
2+ * Copyright 2002-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -173,7 +173,6 @@ public SseBuilder retry(Duration duration) {
173173
174174 @ Override
175175 public SseBuilder comment (String comment ) {
176- Assert .hasLength (comment , "Comment must not be empty" );
177176 String [] lines = comment .split ("\n " );
178177 for (String line : lines ) {
179178 field ("" , line );
Original file line number Diff line number Diff line change 11/*
2- * Copyright 2002-2024 the original author or authors.
2+ * Copyright 2002-2025 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
@@ -173,6 +173,26 @@ void sendWithoutData() throws Exception {
173173 assertThat (this .mockResponse .getContentAsString ()).isEqualTo (expected );
174174 }
175175
176+ @ Test // gh-34608
177+ void sendHeartbeat () throws Exception {
178+ ServerResponse response = ServerResponse .sse (sse -> {
179+ try {
180+ sse .comment ("" ).send ();
181+ }
182+ catch (IOException ex ) {
183+ throw new UncheckedIOException (ex );
184+ }
185+ });
186+
187+ ServerResponse .Context context = Collections ::emptyList ;
188+
189+ ModelAndView mav = response .writeTo (this .mockRequest , this .mockResponse , context );
190+ assertThat (mav ).isNull ();
191+
192+ String expected = ":\n \n " ;
193+ assertThat (this .mockResponse .getContentAsString ()).isEqualTo (expected );
194+ }
195+
176196
177197 private static final class Person {
178198
You can’t perform that action at this time.
0 commit comments