Server-Sent Events (SSE)
Stream JSON events to clients using Server-Sent Events (SSE) at /sse. A web-based tester is available at /web-sse. Events include a counter and timestamp, sent at intervals set by ECHO_SSE_TICKER.
How It Works
graph TD
A[Client Connects] --> B[Set Event Stream]
B --> C{Send Events}
C -->|Ticker| D[Send JSON Event]
C -->|Keep-Alive| E[Send Comment]
C -->|Client Disconnect| F[Close Stream]
D --> C
E --> C
SSE Endpoint
Connect to /sse to receive JSON events.
- Endpoint:
GET /sse - Env:
ECHO_SSE_TICKER=5s(default: 5s) - Example:
curl -N http://localhost:8080/sse
# Response (stream):
# data: {"counter": 1, "timestamp": "2025-09-14T20:07:00Z"}
# data: {"counter": 2, "timestamp": "2025-09-14T20:07:05Z"}
SSE Tester
Access a browser-based tester at /web-sse to view streaming events.
- URL:
http://localhost:8080/web-sse - Features: Display events, monitor connection status.
Notes
- Keep-alive comments sent every 1s to maintain connection.
- No rate limiting applied to SSE (explicitly bypassed).
- Context cancellation closes stream on client disconnect.
- Events are not logged to avoid overhead.