StreamResponseDefinition

open class StreamResponseDefinition<P, T>(val chunkFlow: Flow<T>? = null, val chunks: List<T>? = null, val delayBetweenChunks: Duration = Duration.ZERO, contentType: ContentType = ContentType.Text.EventStream.withCharset(Charsets.UTF_8), chunkContentType: ContentType? = null, httpStatusCode: Int = 200, httpStatus: HttpStatusCode = HttpStatusCode.fromValue(httpStatusCode), headers: ResponseHeaders.() -> Unit? = null, delay: Duration, formatter: HttpFormatter) : AbstractResponseDefinition<T> (source)

Represents a definition for streaming responses, supporting chunked data and flow-based content streaming. This class extends the base AbstractResponseDefinition to provide additional functionality specific to chunked or streamed responses. It can handle flow-based content delivery, manage chunk-wise delays, and supports various output formats such as OutputStream, Writer, or ServerSSESession.

Author

Konstantin Pavlov

Parameters

P

The type of the request body.

T

The type of the response data being streamed.

See also

Inheritors

Constructors

Link copied to clipboard
constructor(chunkFlow: Flow<T>? = null, chunks: List<T>? = null, delayBetweenChunks: Duration = Duration.ZERO, contentType: ContentType = ContentType.Text.EventStream.withCharset(Charsets.UTF_8), chunkContentType: ContentType? = null, httpStatusCode: Int = 200, httpStatus: HttpStatusCode = HttpStatusCode.fromValue(httpStatusCode), headers: ResponseHeaders.() -> Unit? = null, delay: Duration, formatter: HttpFormatter)

Initializes a streaming response definition with the specified flow, chunk list, content type, HTTP status code, and headers.

Properties

Link copied to clipboard
open val chunkFlow: Flow<T>?

A Flow of chunks to be streamed as part of the response.

Link copied to clipboard
val chunks: List<T>?

A list of chunks representing the response data to be sent.

Link copied to clipboard

The MIME type of the response content.

Link copied to clipboard
open val delay: Duration

A delay applied before sending the response. Defaults to Duration.ZERO.

Link copied to clipboard

Delay between the transmission of each chunk.

Link copied to clipboard

A lambda that configures the response headers. Defaults to null.

Link copied to clipboard

The HTTP status code of the response. Defaults to HttpStatusCode.OK.

Link copied to clipboard

The HTTP status code of the response as Int, defaulting to 200.

Link copied to clipboard

The optional response payload associated with this definition.

Functions

Link copied to clipboard
fun withResponseBody(block: T?.() -> T?)

Modifies the response body of this response definition using the provided transformation logic.