Class SseBodyParser
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
When per-chunk timestamps are available (captured by the streaming relay during recording), the parser applies the actual inter-chunk delays to reproduce the original timing. When per-chunk timestamps are absent (legacy recordings), a fixed inter-event delay is applied to each event (except the first). The default fallback is 50 milliseconds.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longDefault inter-event delay in milliseconds when per-chunk timestamps are not available. -
Constructor Summary
ConstructorsConstructorDescriptionCreate a parser with the default inter-event delay.SseBodyParser(long interEventDelayMs) Create a parser with a custom inter-event delay. -
Method Summary
-
Field Details
-
DEFAULT_INTER_EVENT_DELAY_MS
public static final long DEFAULT_INTER_EVENT_DELAY_MSDefault inter-event delay in milliseconds when per-chunk timestamps are not available.- See Also:
-
-
Constructor Details
-
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 Details
-
parse
Parse raw SSE body text into a list ofSseEventobjects.- 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
-
parse
Parse raw SSE body text into a list ofSseEventobjects, optionally applying per-chunk replay timing captured during recording.When
perChunkDelaysMsis non-null and has enough entries, each event (after the first) receives its corresponding captured inter-chunk delay instead of the fixed default. WhenperChunkDelaysMsis null or too short, the fixedinterEventDelayMsfallback is used, preserving backward compatibility with recordings that predate per-chunk timing capture.- Parameters:
sseText- the raw SSE body textperChunkDelaysMs- optional list of inter-chunk delays in milliseconds (index 0 = first chunk delay, typically 0). May be null for fallback behaviour.- Returns:
- the parsed events; empty list if the input is null or blank
-