HttpServerResponse

用于构建并向客户端发送 HTTP 响应的接口。

在服务器的请求处理逻辑中,你可以通过 HttpServerCall.getResponse 访问此对象, 并调用其 respond* 方法来结束请求-响应周期。

注意:一个请求通常只能调用一次 respond* 方法。

Author

M8Test, [email protected], https://m8test.com

Functions

Link copied to clipboard
abstract fun addCookie(cookie: HttpCookie.() -> Unit)

在响应中添加一个 Set-Cookie 头部。

Link copied to clipboard
abstract fun addHeader(name: String, value: Any)

在响应中添加一个 HTTP 头部。

Link copied to clipboard
abstract fun respondBytes(scope: CoroutineScope, byteArray: ByteArray): Job

向客户端发送一个字节数组作为响应体。

Link copied to clipboard
abstract fun respondRedirect(scope: CoroutineScope, url: String, permanent: Boolean): Job

向客户端发送一个重定向响应(状态码 301 或 302)。

Link copied to clipboard
abstract fun respondText(scope: CoroutineScope, text: String, contentType: (ContentTypes) -> ContentType?): Job

向客户端发送一段文本作为响应体。