Package io.karatelabs.http
Class SseConnection
java.lang.Object
io.karatelabs.http.SseConnection
Server-Sent Events connection wrapping a Netty channel.
Sends the initial HTTP response headers with chunked transfer encoding,
then allows sending individual SSE events as data frames.
-
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Close the SSE connection by sending the last chunk and closing the channel.booleanisOpen()voidonDisconnect(Runnable callback) Register a callback for when the client disconnects.voidopen()Commit the SSE response head (200,text/event-stream) now.voidReject this would-be SSE connection with a normal HTTP error response, before any event is sent — for anAccept: text/event-streamrequest that is not actually an event-source route (the MCP Streamable-HTTP spec wants405for a GET to a POST-only endpoint).voidSend an SSE event with data only (no event name).voidSend an SSE event with the given event name and data.voidsendComment(String comment) Send an SSE comment (line starting with colon).
-
Method Details
-
open
public void open()Commit the SSE response head (200,text/event-stream) now. Idempotent; auto-called on the firstsend/sendComment. Call it explicitly to open the stream before any event. -
reject
Reject this would-be SSE connection with a normal HTTP error response, before any event is sent — for anAccept: text/event-streamrequest that is not actually an event-source route (the MCP Streamable-HTTP spec wants405for a GET to a POST-only endpoint). No-op once the stream has been opened. -
send
Send an SSE event with the given event name and data.- Parameters:
event- the event name (appears as "event: name" in the stream)data- the event data (appears as "data: ..." lines)
-
send
Send an SSE event with data only (no event name). -
sendComment
Send an SSE comment (line starting with colon). Useful as a keep-alive. -
close
public void close()Close the SSE connection by sending the last chunk and closing the channel. -
isOpen
public boolean isOpen() -
onDisconnect
Register a callback for when the client disconnects.
-