Skip to content

Commit

Permalink
Merge pull request #137 from KAKAO-TOUR-API-CONTEST/devyj
Browse files Browse the repository at this point in the history
fix : sse buffering
  • Loading branch information
yyujin1231 authored Oct 11, 2024
2 parents 7d68c1e + 99f7612 commit 5f507f5
Showing 1 changed file with 9 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5f507f5

Please sign in to comment.