fix SSE格式
This commit is contained in:
parent
0901ff78a5
commit
2cd64981a1
@ -1,6 +1,5 @@
|
||||
package com.knowledge.base.infrastructure.util.http;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
|
||||
|
||||
import java.io.IOException;
|
||||
@ -15,8 +14,16 @@ public class SseOutputAdapter implements WriterAdapter {
|
||||
|
||||
@Override
|
||||
public void writeLine(String line) throws IOException {
|
||||
if (StrUtil.isNotBlank(line)) {
|
||||
emitter.send(SseEmitter.event().data(line));
|
||||
if (line == null || line.isBlank()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// 如果 line 以 "data: " 开头,则去除该前缀
|
||||
if (line.startsWith("data: ")) {
|
||||
line = line.substring(6).trim();
|
||||
}
|
||||
|
||||
// 发送单行 SSE 事件
|
||||
emitter.send(SseEmitter.event().data(line));
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user