Class SseBodyParser


  • public class SseBodyParser
    extends Object
    Parses raw text/event-stream bytes into a list of SseEvent objects suitable for constructing an HttpSseResponse.

    The parser follows the SSE specification (W3C Server-Sent Events):

    • Events are separated by blank lines (\n\n)
    • Lines starting with data: set the data field
    • Lines starting with event: set the event type
    • Lines starting with id: set the last event ID
    • Lines starting with retry: set the reconnection time
    • Lines starting with : are comments and are ignored
    • Multiple data: lines within one event are joined with \n

    Since per-chunk timestamps are not captured by the streaming relay, a fixed inter-event delay is applied to each event (except the first). The default is 50 milliseconds.

    • Field Detail

      • DEFAULT_INTER_EVENT_DELAY_MS

        public static final long DEFAULT_INTER_EVENT_DELAY_MS
        Default inter-event delay in milliseconds when per-chunk timestamps are not available.
        See Also:
        Constant Field Values
    • Constructor Detail

      • SseBodyParser

        public SseBodyParser()
        Create a parser with the default inter-event delay.
      • SseBodyParser

        public SseBodyParser​(long interEventDelayMs)
        Create a parser with a custom inter-event delay.
        Parameters:
        interEventDelayMs - delay in milliseconds between events on replay
    • Method Detail

      • parse

        public List<SseEvent> parse​(String sseText)
        Parse raw SSE body text into a list of SseEvent objects.
        Parameters:
        sseText - the raw SSE body text (e.g., captured from a forwarded streaming response)
        Returns:
        the parsed events; empty list if the input is null or blank