Class SseResponseHelper
Both the v1 chat API (ChatApiManager) and the v2 chat-stream handler
(ChatStreamHandler) emit text/event-stream responses and need the
same minimum set of response headers to interoperate correctly with browsers and
reverse proxies. This helper centralises that header configuration so the
baseline cannot drift between the two surfaces.
The X-Accel-Buffering: no header is critical when running behind nginx
(or any reverse proxy that defaults to response buffering): without it the entire
stream is buffered until the connection closes, which defeats the purpose of SSE
and breaks the chat UX.
This is a DI-managed singleton helper; obtain it through
ComponentUtil.getSseResponseHelper().
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidapplySseHeaders(jakarta.servlet.http.HttpServletResponse response) Applies the standard SSE response headers to the given response.
-
Constructor Details
-
SseResponseHelper
public SseResponseHelper()Creates the SSE response helper. Registered as the DI componentsseResponseHelperand obtained viaComponentUtil.getSseResponseHelper().
-
-
Method Details
-
applySseHeaders
public void applySseHeaders(jakarta.servlet.http.HttpServletResponse response) Applies the standard SSE response headers to the given response.The following headers are set:
Content-Type: text/event-stream; charset=UTF-8(also sets character encoding)Cache-Control: no-cache— prevent intermediaries from caching the event streamConnection: keep-alive— keep the underlying TCP connection open for streamingX-Accel-Buffering: no— disable response buffering in nginx and similar reverse proxies
Must be called before any bytes are written to the response so the headers are flushed with the response prelude.
- Parameters:
response- the HTTP response to configure; must not benull
-