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:

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 of client.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)
}

Report a problem