parent
9350091163
commit
2530efd1c7
|
|
@ -237,6 +237,9 @@ public class SseEmitter extends ResponseBodyEmitter {
|
|||
public SseEventBuilder data(Object object, @Nullable MediaType mediaType) {
|
||||
append("data:");
|
||||
saveAppendedText();
|
||||
if (object instanceof String text) {
|
||||
object = StringUtils.replace(text, "\n", "\ndata:");
|
||||
}
|
||||
this.dataToSend.add(new DataWithMediaType(object, mediaType));
|
||||
append('\n');
|
||||
return this;
|
||||
|
|
|
|||
|
|
@ -104,6 +104,16 @@ public class SseEmitterTests {
|
|||
this.handler.assertWriteCount(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendEventWithMultiline() throws Exception {
|
||||
this.emitter.send(event().data("foo\nbar\nbaz"));
|
||||
this.handler.assertSentObjectCount(3);
|
||||
this.handler.assertObject(0, "data:", TEXT_PLAIN_UTF8);
|
||||
this.handler.assertObject(1, "foo\ndata:bar\ndata:baz");
|
||||
this.handler.assertObject(2, "\n\n", TEXT_PLAIN_UTF8);
|
||||
this.handler.assertWriteCount(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void sendEventFull() throws Exception {
|
||||
this.emitter.send(event().comment("blah").name("test").reconnectTime(5000L).id("1").data("foo"));
|
||||
|
|
|
|||
Loading…
Reference in New Issue