Represents a server-side HTTP response. Instances of this class are created and associated to every instance of HttpServerRequest that is created. 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.

Instances of this class are not thread-safe.

By: Julien Viet

no subtypes hierarchy

HttpServerResponse(HttpServerResponse delegate)
chunkedshared actual Boolean chunked

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 {@code Transfer-Encoding} with a value of {@code Chunked} will be automatically inserted in the response.

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

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

streamshared actual WriteStream stream

The write stream of this request

Inherited Attributes
Attributes inherited from: Object
hash, string
closeshared void close()

Close the underlying TCP connection

endshared actual HttpServerResponse end(Chunk? chunk)

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.

headersshared actual HttpServerResponse headers(Entries headers)

Set the response headers.

sendFileshared Promise<Anything> sendFile(String fileName, String? notFoundFile = null)

Tell the kernel 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. It also takes the path notFoundFile to a resource to serve if the resource is not found

  • notFoundFile = null
statusshared HttpServerResponse status(Integer code, String? message = null)

Set the status code.

  • code

    the status code value

  • message = null

    the status message

trailersshared HttpServerResponse trailers(Entries trailers)
writeshared actual HttpServerResponse write(Chunk chunk)

Write a chunk to the output body.

Inherited Methods
Methods inherited from: HttpOutput<O>
Methods inherited from: Object