interface HttpServerResponse : WriteStream<Buffer>
Represents a server-side HTTP response.
An instance of this is created and associated to every instance of HttpServerRequest that.
It allows the developer to control the HTTP response that is sent back to the client for a particular HTTP request.
It contains methods that allow HTTP headers and trailers to be set, and for a body to be written out to the response.
It also allows files to be streamed by the kernel directly from disk to the outgoing HTTP connection, bypassing user space altogether (where supported by the underlying operating system). This is a very efficient way of serving files from the server since buffers do not have to be read one by one from the file and written to the outgoing socket.
It implements io.vertx.core.streams.WriteStream so it can be used with io.vertx.core.streams.Pump to pump data with flow control.
Author
Tim Fox
abstract fun bodyEndHandler(handler: Handler<Void>): HttpServerResponse
Provides a handler that will be called after the last part of the body is written to the wire. The handler is called asynchronously of when the response has been received by the client. This provides a hook allowing you to do more operations once the request has been sent over the wire such as resource cleanup. |
|
abstract fun bytesWritten(): Long |
|
abstract fun close(): Unit
Close the underlying TCP connection corresponding to the request. |
|
abstract fun closeHandler(handler: Handler<Void>): HttpServerResponse
Set a close handler for the response, this is called when the underlying connection is closed and the response was still using the connection. For HTTP/1.x it is called when the connection is closed before For HTTP/2 it is called when the related stream is closed, and therefore it will be always be called. |
|
abstract fun closed(): Boolean |
|
abstract fun drainHandler(handler: Handler<Void>): HttpServerResponse |
|
abstract fun end(chunk: String): Unit
Same as abstract fun end(chunk: String, enc: String): Unit
Same as abstract fun end(chunk: Buffer): Unit
Same as abstract fun end(): Unit
Ends the response. If no data has been written to the response body, the actual response won't get written until this method gets called. Once the response has ended, it cannot be used any more. |
|
abstract fun endHandler(handler: Handler<Void>): HttpServerResponse
Set an end handler for the response. This will be called when the response is disposed to allow consistent cleanup of the response. |
|
abstract fun ended(): Boolean |
|
abstract fun exceptionHandler(handler: Handler<Throwable>): HttpServerResponse |
|
abstract fun getStatusCode(): Int |
|
abstract fun getStatusMessage(): String |
|
abstract fun headWritten(): Boolean |
|
abstract fun headers(): MultiMap |
|
abstract fun headersEndHandler(handler: Handler<Void>): HttpServerResponse
Provide a handler that will be called just before the headers are written to the wire. This provides a hook allowing you to add any more headers or do any more operations before this occurs. |
|
abstract fun isChunked(): Boolean |
|
abstract fun push(method: HttpMethod, host: String, path: String, handler: Handler<AsyncResult<HttpServerResponse>>): HttpServerResponse
Like abstract fun push(method: HttpMethod, path: String, headers: MultiMap, handler: Handler<AsyncResult<HttpServerResponse>>): HttpServerResponseabstract fun push(method: HttpMethod, path: String, handler: Handler<AsyncResult<HttpServerResponse>>): HttpServerResponse
Like abstract fun push(method: HttpMethod, host: String, path: String, headers: MultiMap, handler: Handler<AsyncResult<HttpServerResponse>>): HttpServerResponse
Push a response to the client. The |
|
abstract fun putHeader(name: String, value: String): HttpServerResponse
Put an HTTP header abstract fun putHeader(name: CharSequence, value: CharSequence): HttpServerResponse
Like abstract fun putHeader(name: String, values: MutableIterable<String>): HttpServerResponse
Like abstract fun putHeader(name: CharSequence, values: MutableIterable<CharSequence>): HttpServerResponse
Like |
|
abstract fun putTrailer(name: String, value: String): HttpServerResponse
Put an HTTP trailer abstract fun putTrailer(name: CharSequence, value: CharSequence): HttpServerResponse
Like abstract fun putTrailer(name: String, values: MutableIterable<String>): HttpServerResponse
Like abstract fun putTrailer(name: CharSequence, value: MutableIterable<CharSequence>): HttpServerResponse
Like |
|
open fun reset(): Unit
Reset this HTTP/2 stream with the error code abstract fun reset(code: Long): Unit
Reset this HTTP/2 stream with the error |
|
open fun sendFile(filename: String): HttpServerResponse
Same as open fun sendFile(filename: String, offset: Long): HttpServerResponse
Same as abstract fun sendFile(filename: String, offset: Long, length: Long): HttpServerResponse
Ask the OS to stream a file as specified by The actual serve is asynchronous and may not complete until some time after this method has returned. open fun sendFile(filename: String, resultHandler: Handler<AsyncResult<Void>>): HttpServerResponse
Like open fun sendFile(filename: String, offset: Long, resultHandler: Handler<AsyncResult<Void>>): HttpServerResponse
Like abstract fun sendFile(filename: String, offset: Long, length: Long, resultHandler: Handler<AsyncResult<Void>>): HttpServerResponse
Like |
|
abstract fun setChunked(chunked: Boolean): HttpServerResponse
If If chunked encoding is used the HTTP header If An HTTP chunked response is typically used when you do not know the total size of the request body up front. |
|
abstract fun setStatusCode(statusCode: Int): HttpServerResponse
Set the status code. If the status message hasn't been explicitly set, a default status message corresponding to the code will be looked-up and used. |
|
abstract fun setStatusMessage(statusMessage: String): HttpServerResponse
Set the status message |
|
abstract fun setWriteQueueMaxSize(maxSize: Int): HttpServerResponse |
|
abstract fun streamId(): Int |
|
abstract fun trailers(): MultiMap |
|
abstract fun write(data: Buffer): HttpServerResponseabstract fun write(chunk: String, enc: String): HttpServerResponse
Write a String to the response body, encoded using the encoding abstract fun write(chunk: String): HttpServerResponse
Write a String to the response body, encoded in UTF-8. |
|
abstract fun writeContinue(): HttpServerResponse
Used to write an interim 100 Continue response to signify that the client should send the rest of the request. Must only be used if the request contains an "Expect:100-Continue" header |
|
abstract fun writeCustomFrame(type: Int, flags: Int, payload: Buffer): HttpServerResponse
Write an HTTP/2 frame to the response, allowing to extend the HTTP/2 protocol. The frame is sent immediatly and is not subject to flow control. open fun writeCustomFrame(frame: HttpFrame): HttpServerResponse
Like |