Class: HttpServerResponse

vertx/http. HttpServerResponse

new HttpServerResponse(jresp)

A server-side HTTP response. An instance of this class is created and associated to every instance of module:vertx/http.HttpServerRequest that is created.

It allows the developer to control the HTTP response that is sent back to the client for a partcular 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.

Parameters:
Name Type Description
jresp org.vertx.java.core.http.HttpServerResponse the underlying java proxy
Source:

Extends

Methods

chunked(chunked) → {boolean|module:vertx/http.HttpServerResponse}

Get or set if the response is chunked
Parameters:
Name Type Argument Description
chunked boolean <optional>
Whether or not the response will be chunked encoding
Source:
Returns:
Type
boolean | module:vertx/http.HttpServerResponse

drainHandler(handler)

Set a drain handler on the stream. If the write queue is full, then the handler will be called when the write queue has been reduced to maxSize/2. See module:vertx/pump~Pump for an example of this being used.
Parameters:
Name Type Description
handler Handler the handler to call when the stream has been drained
Inherited From:
Source:

end(chunk, encoding)

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.

Parameters:
Name Type Argument Description
chunk string <optional>
a string to write to the data stream before closing
encoding string <optional>
the encoding to use for the write (default is UTF-8)
Source:

exceptionHandler(handler)

Set an exception handler on the stream
Parameters:
Name Type Description
handler Handler the handler to call when an exception occurs
Inherited From:
Source:

headers() → {module:vertx/multi_map~MultiMap}

Return the http headers of the response
Source:
Returns:
Type
module:vertx/multi_map~MultiMap

putHeader(headerName, headerValue) → {module:vertx/http.HttpServerResponse}

Put a header on the response.
Parameters:
Name Type Description
headerName string The name under which the header should be stored
headerValue string T the value of the header
Source:
Returns:
Type
module:vertx/http.HttpServerResponse

putTrailer(trailerName, trailerValue) → {module:vertx/http.HttpServerResponse}

Put a trailing header
Parameters:
Name Type Description
trailerName string The name under which the header should be stored
trailerValue string The value of the trailer
Source:
Returns:
Type
module:vertx/http.HttpServerResponse

sendFile(fileName, notFoundFile, handler) → {module:vertx/http.HttpServerResponse}

Tell the kernel to stream a file 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.
Parameters:
Name Type Argument Description
fileName string Path to file to send.
notFoundFile string <optional>
Path to a file to send if fileName can't be found.
handler ResultHandler <optional>
Function to be called when send has completed (or failed).
Source:
Returns:
Type
module:vertx/http.HttpServerResponse

sendHead() → {module:vertx/http.HttpServerResponse}

Forces the head of the request to be written before end is called on the request. This is normally used to implement HTTP 100-continue handling, see continue_handler for more information.
Source:
Returns:
Type
module:vertx/http.HttpServerResponse

statusCode(code) → {number|module:vertx/http.HttpServerResponse}

Get or set HTTP status code of the response.
Parameters:
Name Type Argument Description
code number <optional>
The HTTP status code, e.g. 200
Source:
Returns:
If a status code is supplied, this method sets it and returns itself. If a status code is not provided, return the current status code for this response.
Type
number | module:vertx/http.HttpServerResponse

statusMessage(message) → {string|module:vertx/http.HttpServerResponse}

Get or set HTTP status message of the response.
Parameters:
Name Type Argument Description
message string <optional>
The HTTP status message.
Source:
Returns:
Type
string | module:vertx/http.HttpServerResponse

trailers() → {module:vertx/multi_map~MultiMap}

Return the trailing headers of the response
Source:
Returns:
Type
module:vertx/multi_map~MultiMap

write(body, encoding) → {module:vertx/http.HttpServerResponse}

Write content to the response
Parameters:
Name Type Argument Description
body string The body of the response.
encoding string <optional>
The character encoding, defaults to UTF-8
Source:
Returns:
Returns self
Type
module:vertx/http.HttpServerResponse

writeQueueFull()

This will return true if there are more bytes in the write queue than the value set using writeQueueMaxSize
Inherited From:
Source:

writeQueueMaxSize(size)

Set the maximum size of the write queue to maxSize. You will still be able to write to the stream even if there is more than maxSize bytes in the write queue. This is used as an indicator by classes such as Pump to provide flow control.
Parameters:
Name Type Description
size number the size of the write queue
Inherited From:
Source: