From 4b5910f97272fdeea053fddfa795eb9e00d17d14 Mon Sep 17 00:00:00 2001 From: cherishsince Date: Sun, 14 Apr 2024 15:51:57 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=20Utf8SseEmitter=20=E5=A4=84?= =?UTF-8?q?=E7=90=86=20=E4=B8=AD=E6=96=87=E4=B9=B1=E7=A0=81=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../module/ai/controller/Utf8SseEmitter.java | 26 +++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/Utf8SseEmitter.java diff --git a/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/Utf8SseEmitter.java b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/Utf8SseEmitter.java new file mode 100644 index 000000000..d23f4e9b1 --- /dev/null +++ b/yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/Utf8SseEmitter.java @@ -0,0 +1,26 @@ +package cn.iocoder.yudao.module.ai.controller; + +import org.springframework.http.HttpHeaders; +import org.springframework.http.MediaType; +import org.springframework.http.server.ServerHttpResponse; +import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; + +import java.nio.charset.StandardCharsets; + +/** + * 解决中文乱码 + * + * @author fansili + * @time 2024/4/14 15:13 + * @since 1.0 + */ +public class Utf8SseEmitter extends SseEmitter { + + @Override + protected void extendResponse(ServerHttpResponse outputMessage) { + super.extendResponse(outputMessage); + + HttpHeaders headers = outputMessage.getHeaders(); + headers.setContentType(new MediaType(MediaType.TEXT_EVENT_STREAM, StandardCharsets.UTF_8)); + } +}