bufferPolicy
Controls how the plugin captures a diagnostic buffer of the SSE stream that has already been processed, so you can inspect it when an exception occurs.
The buffer is built from bytes the SSE reader has already read, it does not re-read the network.
Variants:
SSEBufferPolicy.Off — capture is disabled (default).
SSEBufferPolicy.LastLines — keeps the last N text lines of the stream.
SSEBufferPolicy.LastEvent — keeps the last completed SSE event.
SSEBufferPolicy.LastEvents — keeps the last K completed SSE events.
SSEBufferPolicy.All — keeps everything that has been read so far. Please note that this may consume a lot of memory.
Notes:
This policy applies to failures after the SSE stream has started (e.g., parsing errors or exceptions thrown inside your
client.sse { ... }
block). It does not affect "handshake" failures (non-2xx status or non-text/event-stream
); those are handled separately.The buffer reflects only what has already been consumed by the SSE parser at the moment of failure.
You can override the global policy per call via the
bufferPolicy
parameter ofclient.sse(...)
.
Usage:
install(SSE) {
bufferPolicy = SSEBufferPolicy.LastEvents(5)
}
try {
client.sse("https://example.com/sse") {
incoming.collect { /* ... */}
}
} catch (e: SSEClientException) {
val text = e.response?.bodyAsText() // contains the last 5 events received
println(text)
}