Server-Sent Event Parser

Parse a complete Unicode event stream into dispatched events, preserving last-event IDs and discarding an unterminated final event.

Description

Server-sent events are line-based records dispatched at blank lines.

Server-sent events are line-based records dispatched at blank lines. Event IDs persist across records, while repeated data lines form one newline-joined payload.1

Parse a complete Unicode event stream into dispatched events, preserving last-event IDs and discarding an unterminated final event.

When to use Server-Sent Event Parser

Use this tool to parse a complete Unicode event stream into dispatched events, preserving last-event IDs and discarding an unterminated final event.

Choose the URL, decoded source text, header value or explicit byte list requested by this tool. Paste the complete relevant input and follow its parsing and encoding conventions.

How to use Server-Sent Event Parser and understand its results

  1. Choose the URL, decoded source text, header value or explicit byte list requested by this tool. Paste the complete relevant input and follow its parsing and encoding conventions.
  2. Enter stream using the field table and calculation rules, then run the tool.
  3. Read events, lastEventId, retryMs. The explanation below defines the units, signs, ordering and any flags or placeholder values.
  4. If the tool reports an input issue, correct the values and run it again. Apply the stated assumptions when interpreting a successfully returned result.
Input fieldMeaningValue type; see rules belowRequirement
streamComplete decoded UTF-8 event stream.string; maximum length: 1000000Required

Paste a complete already decoded UTF-8 event stream. Remove an initial BOM and process terminated CRLF, CR or LF lines. Ignore comments, strip one leading field-value space, default event type to message and persist accepted IDs. NUL-containing IDs are ignored; digit-only safe-integer retry values update retryMs. Return dispatched records and final ID/retry state.

on terminated blank line: dispatch if dataLines exist; data=join(dataLines,'\n')

Units, indexing, boundary conditions and exceptional cases are defined in the calculation rules above.

Output fieldMeaningValue type
eventsDispatched events.list of object; minimum entries: 0; maximum entries: 100000
lastEventIdMost recent valid event ID.string; maximum length: 1000000
retryMsLast safe reconnection interval, or null if no valid retry was supplied.JSON value
json
{
  "input": {
    "stream": "id: 7\nevent: update\ndata: first\ndata: second\n\nretry: 1500\n\n"
  },
  "output": {
    "events": [
      {
        "event": "update",
        "data": "first\nsecond",
        "id": "7"
      }
    ],
    "lastEventId": "7",
    "retryMs": 1500
  }
}

Limitations and assumptions

An unterminated final line or undispatched final event is discarded. This does not maintain incremental parser state across runs, connect to a server or schedule reconnection.

Numeric inputs must be finite. Follow the calculation-specific rules for overflow, underflow and exceptional cases. Extremely large text inputs are rejected. Missing required fields, extra fields, wrong value types and violations of the calculation rules are input errors.

Alternative or Complementary methods

Use Meta Tag Parser: Extract named meta entries from HTML source in document order, preserving repeated keys. For a complementary task, use Subresource Integrity Hash Generator: Hash explicit UTF-8 text with SHA-256, SHA-384, or SHA-512 and emit Base64 Subresource Integrity metadata.

References

  1. Server-Sent Event Parser — tool.io

Similar or alternative tools

Don't forget to set a bookmark for tool.io!
Privacy | Imprint | Cookies