Commit 4b5910f97272fdeea053fddfa795eb9e00d17d14
1 parent
8b310c1d
增加 Utf8SseEmitter 处理 中文乱码问题
Showing
1 changed file
with
26 additions
and
0 deletions
yudao-module-ai/yudao-module-ai-biz/src/main/java/cn/iocoder/yudao/module/ai/controller/Utf8SseEmitter.java
0 → 100644
| 1 | +package cn.iocoder.yudao.module.ai.controller; | |
| 2 | + | |
| 3 | +import org.springframework.http.HttpHeaders; | |
| 4 | +import org.springframework.http.MediaType; | |
| 5 | +import org.springframework.http.server.ServerHttpResponse; | |
| 6 | +import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; | |
| 7 | + | |
| 8 | +import java.nio.charset.StandardCharsets; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * 解决中文乱码 | |
| 12 | + * | |
| 13 | + * @author fansili | |
| 14 | + * @time 2024/4/14 15:13 | |
| 15 | + * @since 1.0 | |
| 16 | + */ | |
| 17 | +public class Utf8SseEmitter extends SseEmitter { | |
| 18 | + | |
| 19 | + @Override | |
| 20 | + protected void extendResponse(ServerHttpResponse outputMessage) { | |
| 21 | + super.extendResponse(outputMessage); | |
| 22 | + | |
| 23 | + HttpHeaders headers = outputMessage.getHeaders(); | |
| 24 | + headers.setContentType(new MediaType(MediaType.TEXT_EVENT_STREAM, StandardCharsets.UTF_8)); | |
| 25 | + } | |
| 26 | +} | ... | ... |