fix(streaming): 修正流式输出的端点URL和防缓冲header
前端: - kieaiGeminiChatStream URL 从 /gemini/chat 改为 /gemini/chat/stream (后者声明了 produces=text/event-stream,nginx 不会缓冲) - 请求 header 增加 Accept: text/event-stream 后端: - KieAIController.geminiChatStream 补充防缓冲 header: X-Accel-Buffering: no + Cache-Control: no-cache (与 CozeController.chatStream 对齐,防止 nginx 缓冲 SSE) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -17,6 +17,7 @@ import com.zbkj.service.service.tool.ToolSora2Service;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import io.swagger.annotations.ApiParam;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@@ -86,7 +87,11 @@ public class KieAIController {
|
||||
*/
|
||||
@PostMapping(value = "/gemini/chat/stream", produces = "text/event-stream")
|
||||
@ApiOperation(value = "Gemini 2.5 Flash 流式对话", notes = "使用 SSE 实时推送响应")
|
||||
public SseEmitter geminiChatStream(@RequestBody @Validated KieAIGeminiChatRequest request) {
|
||||
public SseEmitter geminiChatStream(@RequestBody @Validated KieAIGeminiChatRequest request,
|
||||
HttpServletResponse response) {
|
||||
// 防止 nginx 缓冲 SSE 响应(与 CozeController.chatStream 对齐)
|
||||
response.setHeader("X-Accel-Buffering", "no");
|
||||
response.setHeader("Cache-Control", "no-cache");
|
||||
request.setStream(true);
|
||||
return toolKieAIService.geminiChatStream(request);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user