WebFlux support for SSE with multiline fragments
See gh-33194
This commit is contained in:
@@ -30,6 +30,7 @@ import org.springframework.http.server.ServerHttpResponse;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
/**
|
||||
* A specialization of {@link ResponseBodyEmitter} for sending
|
||||
@@ -203,6 +204,8 @@ public class SseEmitter extends ResponseBodyEmitter {
|
||||
@Nullable
|
||||
private StringBuilder sb;
|
||||
|
||||
private boolean hasName;
|
||||
|
||||
@Override
|
||||
public SseEventBuilder id(String id) {
|
||||
append("id:").append(id).append('\n');
|
||||
@@ -211,6 +214,7 @@ public class SseEmitter extends ResponseBodyEmitter {
|
||||
|
||||
@Override
|
||||
public SseEventBuilder name(String name) {
|
||||
this.hasName = true;
|
||||
append("event:").append(name).append('\n');
|
||||
return this;
|
||||
}
|
||||
@@ -234,6 +238,9 @@ public class SseEmitter extends ResponseBodyEmitter {
|
||||
|
||||
@Override
|
||||
public SseEventBuilder data(Object object, @Nullable MediaType mediaType) {
|
||||
if (object instanceof ModelAndView mav && !this.hasName && mav.getViewName() != null) {
|
||||
name(mav.getViewName());
|
||||
}
|
||||
append("data:");
|
||||
saveAppendedText();
|
||||
if (object instanceof String text) {
|
||||
|
||||
Reference in New Issue
Block a user