HttpResponsePort.kt

  1. package com.hexagonkt.http.model

  2. import com.hexagonkt.http.model.ws.WsSession

  3. interface HttpResponsePort : HttpMessage {
  4.     val status: HttpStatus

  5.     val contentLength: Long                        // length of response.body (or 0)

  6.     val onConnect: WsSession.() -> Unit
  7.     val onBinary: WsSession.(data: ByteArray) -> Unit
  8.     val onText: WsSession.(text: String) -> Unit
  9.     val onPing: WsSession.(data: ByteArray) -> Unit
  10.     val onPong: WsSession.(data: ByteArray) -> Unit
  11.     val onClose: WsSession.(status: Int, reason: String) -> Unit

  12.     fun with(
  13.         status: HttpStatus = this.status,
  14.         body: Any = this.body,
  15.         headers: Headers = this.headers,
  16.         contentType: ContentType? = this.contentType,
  17.         cookies: List<Cookie> = this.cookies,
  18.         onConnect: WsSession.() -> Unit = this.onConnect,
  19.         onBinary: WsSession.(data: ByteArray) -> Unit = this.onBinary,
  20.         onText: WsSession.(text: String) -> Unit = this.onText,
  21.         onPing: WsSession.(data: ByteArray) -> Unit = this.onPing,
  22.         onPong: WsSession.(data: ByteArray) -> Unit = this.onPong,
  23.         onClose: WsSession.(status: Int, reason: String) -> Unit = this.onClose,
  24.     ): HttpResponsePort

  25.     operator fun plus(header: Header): HttpResponsePort =
  26.         with(headers = headers + header)

  27.     operator fun plus(cookie: Cookie): HttpResponsePort =
  28.         with(cookies = cookies + cookie)

  29.     operator fun plus(headers: Headers): HttpResponsePort =
  30.         with(headers = this.headers + headers)

  31.     operator fun plus(cookies: List<Cookie>): HttpResponsePort =
  32.         with(cookies = this.cookies + cookies)
  33. }