vertx / io.vertx.rxjava.core.http / HttpServerResponse

HttpServerResponse

open class HttpServerResponse : WriteStream<Buffer>

Represents a server-side HTTP response.

An instance of this is created and associated to every instance of io.vertx.rxjava.core.http.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.rxjava.core.streams.WriteStream so it can be used with io.vertx.rxjava.core.streams.Pump to pump data with flow control.

NOTE: This class has been automatically generated from the io.vertx.core.http.HttpServerResponse non RX-ified interface using Vert.x codegen.

Constructors

<init>

HttpServerResponse(delegate: HttpServerResponse)

Properties

__TYPE_ARG

static val __TYPE_ARG: TypeArg<HttpServerResponse>

Functions

bodyEndHandler

open 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.

bytesWritten

open fun bytesWritten(): Long

close

open fun close(): Unit

Close the underlying TCP connection corresponding to the request.

closeHandler

open 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 end() is called, therefore it is not guaranteed to be called.

For HTTP/2 it is called when the related stream is closed, and therefore it will be always be called.

closed

open fun closed(): Boolean

drainHandler

open fun drainHandler(handler: Handler<Void>): HttpServerResponse

end

open fun end(chunk: String): Unit

Same as io.vertx.rxjava.core.http.HttpServerResponse#end but writes a String in UTF-8 encoding before ending the response.

open fun end(chunk: String, enc: String): Unit

Same as io.vertx.rxjava.core.http.HttpServerResponse#end but writes a String with the specified encoding before ending the response.

open fun end(chunk: Buffer): Unit

Same as io.vertx.rxjava.core.http.HttpServerResponse#end but writes some data to the response body before ending. If the response is not chunked and no other data has been written then the @code{Content-Length} header will be automatically set.

open 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.

endHandler

open 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.

ended

open fun ended(): Boolean

equals

open fun equals(other: Any?): Boolean

exceptionHandler

open fun exceptionHandler(handler: Handler<Throwable>): HttpServerResponse

getDelegate

open fun getDelegate(): HttpServerResponse

getStatusCode

open fun getStatusCode(): Int

getStatusMessage

open fun getStatusMessage(): String

hashCode

open fun hashCode(): Int

headWritten

open fun headWritten(): Boolean

headers

open fun headers(): MultiMap

headersEndHandler

open 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.

isChunked

open fun isChunked(): Boolean

newInstance

open static fun newInstance(arg: HttpServerResponse): HttpServerResponse

push

open fun push(method: HttpMethod, host: String, path: String, handler: Handler<AsyncResult<HttpServerResponse>>): HttpServerResponse

Like io.vertx.rxjava.core.http.HttpServerResponse#push with no headers.

open fun push(method: HttpMethod, path: String, headers: MultiMap, handler: Handler<AsyncResult<HttpServerResponse>>): HttpServerResponse
open fun push(method: HttpMethod, path: String, handler: Handler<AsyncResult<HttpServerResponse>>): HttpServerResponse

Like io.vertx.rxjava.core.http.HttpServerResponse#push with the host copied from the current request.

open fun push(method: HttpMethod, host: String, path: String, headers: MultiMap, handler: Handler<AsyncResult<HttpServerResponse>>): HttpServerResponse

Push a response to the client. The handler will be notified with a success when the push can be sent and with a failure when the client has disabled push or reset the push before it has been sent. The handler may be queued if the client has reduced the maximum number of streams the server can push concurrently. Push can be sent only for peer initiated streams and if the response is not ended.

putHeader

open fun putHeader(name: String, value: String): HttpServerResponse

Put an HTTP header

putTrailer

open fun putTrailer(name: String, value: String): HttpServerResponse

Put an HTTP trailer

reset

open fun reset(): Unit

Reset this HTTP/2 stream with the error code 0.

open fun reset(code: Long): Unit

Reset this HTTP/2 stream with the error code.

rxPush

open fun rxPush(method: HttpMethod, path: String): Single<HttpServerResponse>

Like io.vertx.rxjava.core.http.HttpServerResponse#push with the host copied from the current request.

open fun rxPush(method: HttpMethod, host: String, path: String, headers: MultiMap): Single<HttpServerResponse>

Push a response to the client. The handler will be notified with a success when the push can be sent and with a failure when the client has disabled push or reset the push before it has been sent. The handler may be queued if the client has reduced the maximum number of streams the server can push concurrently. Push can be sent only for peer initiated streams and if the response is not ended.

rxSendFile

open fun rxSendFile(filename: String): Single<Void>
open fun rxSendFile(filename: String, offset: Long): Single<Void>
open fun rxSendFile(filename: String, offset: Long, length: Long): Single<Void>

Like io.vertx.rxjava.core.http.HttpServerResponse#sendFile but providing a handler which will be notified once the file has been completely written to the wire.

sendFile

open fun sendFile(filename: String): HttpServerResponse

Same as io.vertx.rxjava.core.http.HttpServerResponse#sendFile using offset @code{0} which means starting from the beginning of the file.

open fun sendFile(filename: String, offset: Long): HttpServerResponse

Same as io.vertx.rxjava.core.http.HttpServerResponse#sendFile using length @code{Long.MAX_VALUE} which means until the end of the file.

open fun sendFile(filename: String, offset: Long, length: Long): HttpServerResponse

Ask the OS to stream a file as specified by filename directly from disk to the outgoing connection, bypassing userspace altogether (where supported by the underlying operating system. This is a very efficient way to serve files.

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
open fun sendFile(filename: String, offset: Long, resultHandler: Handler<AsyncResult<Void>>): HttpServerResponse
open fun sendFile(filename: String, offset: Long, length: Long, resultHandler: Handler<AsyncResult<Void>>): HttpServerResponse

Like io.vertx.rxjava.core.http.HttpServerResponse#sendFile but providing a handler which will be notified once the file has been completely written to the wire.

setChunked

open fun setChunked(chunked: Boolean): HttpServerResponse

If chunked is true, this response will use HTTP chunked encoding, and each call to write to the body will correspond to a new HTTP chunk sent on the wire.

If chunked encoding is used the HTTP header Transfer-Encoding with a value of Chunked will be automatically inserted in the response.

If chunked is false, this response will not use HTTP chunked encoding, and therefore the total size of any data that is written in the respone body must be set in the Content-Length header before any data is written out.

An HTTP chunked response is typically used when you do not know the total size of the request body up front.

setStatusCode

open 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.

setStatusMessage

open fun setStatusMessage(statusMessage: String): HttpServerResponse

Set the status message

setWriteQueueMaxSize

open fun setWriteQueueMaxSize(maxSize: Int): HttpServerResponse

streamId

open fun streamId(): Int

toString

open fun toString(): String

trailers

open fun trailers(): MultiMap

write

open fun write(data: Buffer): HttpServerResponseopen fun write(chunk: String, enc: String): HttpServerResponse

Write a java.lang.String to the response body, encoded using the encoding enc.

open fun write(chunk: String): HttpServerResponse

Write a java.lang.String to the response body, encoded in UTF-8.

writeContinue

open 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

writeCustomFrame

open 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 io.vertx.rxjava.core.http.HttpServerResponse#writeCustomFrame but with an io.vertx.rxjava.core.http.HttpFrame.

writeQueueFull

open fun writeQueueFull(): Boolean

This will return true if there are more bytes in the write queue than the value set using io.vertx.rxjava.core.http.HttpServerResponse#setWriteQueueMaxSize