WebSocketUpgrade

class WebSocketUpgrade : ProtocolUpgrade

An OutgoingContent response object that could be used to respond(): it will cause application engine to perform HTTP upgrade and start websocket RAW session.

Please note that you generally shouldn’t use this object directly but use WebSockets feature with routing builders webSocket instead.

handle function is applied to a session and as far as it is a RAW session, you should handle all low-level frames yourself and deal with ping/pongs, timeouts, close frames, frame fragmentation and so on.

Parameters

call - that is starting web socket session

protocol - web socket negotiated protocol name (optional)

handle - function that is started once HTTP upgrade complete and the session will end once this function exit

Constructors

<init>

WebSocketUpgrade(
    call: ApplicationCall,
    protocol: String? = null,
    handle: suspend WebSocketSession.() -> Unit)

An OutgoingContent response object that could be used to respond(): it will cause application engine to perform HTTP upgrade and start websocket RAW session.

Properties

call

val call: ApplicationCall

that is starting web socket session

handle

val handle: suspend WebSocketSession.() -> Unit

function that is started once HTTP upgrade complete and the session will end once this function exit

headers

val headers: Headers

Headers to set when sending this content

protocol

val protocol: String?

web socket negotiated protocol name (optional)

Inherited Properties

status

val status: HttpStatusCode?

Status code to set when sending this content

Functions

upgrade

suspend fun upgrade(
    input: ByteReadChannel,
    output: ByteWriteChannel,
    engineContext: <ERROR CLASS>,
    userContext: <ERROR CLASS>
): Job

Upgrades an HTTP connection

Extension Properties

caching

Gets or sets CacheControl instance as an extension property on this content

defaultVersions

val OutgoingContent.defaultVersions: List<Version>

Retrieves LastModified and ETag versions from this OutgoingContent headers

versions

Gets or sets list of Version instances as an extension property on this content

Extension Functions

toByteArray

suspend fun OutgoingContent.toByteArray(): ByteArray

toByteReadPacket

suspend fun OutgoingContent.toByteReadPacket(): ByteReadPacket

wrapHeaders

fun OutgoingContent.wrapHeaders(
    block: (Headers) -> Headers
): OutgoingContent

Generates a new OutgoingContent of the same abstract type but with OutgoingContent.headers transformed by the specified block.