From 99f7612727abcf3d195311fd24fe86109ff919a8 Mon Sep 17 00:00:00 2001 From: Yujin Lee Date: Sat, 12 Oct 2024 03:24:04 +0900 Subject: [PATCH] fix : sse buffering --- .../com/example/ai_jeju/controller/ChatController.java | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/main/java/com/example/ai_jeju/controller/ChatController.java b/src/main/java/com/example/ai_jeju/controller/ChatController.java index 698d572..81be2f1 100644 --- a/src/main/java/com/example/ai_jeju/controller/ChatController.java +++ b/src/main/java/com/example/ai_jeju/controller/ChatController.java @@ -9,6 +9,7 @@ import com.example.ai_jeju.repository.ChatRoomRepository; import com.example.ai_jeju.service.ChatService; import com.example.ai_jeju.service.NotificationService; +import jakarta.servlet.http.HttpServletResponse; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; @@ -20,6 +21,8 @@ import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; +import org.springframework.web.context.request.RequestContextHolder; +import org.springframework.web.context.request.ServletRequestAttributes; import org.springframework.web.servlet.mvc.method.annotation.SseEmitter; import software.amazon.ion.Timestamp; @@ -115,10 +118,16 @@ public SseEmitter subscribeToRoom(@PathVariable("roomId") Long roomId, @RequestP String accessToken = token.replace("Bearer ", ""); log.info("Processed access token: " + accessToken); + if (tokenProvider.validToken(accessToken)) { Long userId = tokenProvider.getUserId(accessToken); log.info("User ID extracted from token: " + userId); + HttpServletResponse response = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getResponse(); + if (response != null) { + response.setHeader("X-Accel-Buffering", "no"); + } + return notificationService.subscribeToRoom(userId); } else { log.error("Invalid token: " + accessToken);