Class: HttpServerResponse

vertx-js/http_server_response~ HttpServerResponse

new HttpServerResponse()

Represents a server-side HTTP response.

An instance of this is created and associated to every instance of

Source:

Methods

bodyEndHandler(handler) → {HttpServerResponse}

Provide a handler that will be called just before the last part of the body is written to the wire and the response is ended.

This provides a hook allowing you to do any more operations before this occurs.

Parameters:
Name Type Description
handler function the handler
Source:
Returns:
a reference to this, so the API can be used fluently
Type
HttpServerResponse

close()

Close the underlying TCP connection corresponding to the request.
Source:

closeHandler(handler) → {HttpServerResponse}

Set a close handler for the response. This will be called if the underlying connection closes before the response is complete.
Parameters:
Name Type Description
handler function the handler
Source:
Returns:
a reference to this, so the API can be used fluently
Type
HttpServerResponse

drainHandler(handler) → {HttpServerResponse}

Parameters:
Name Type Description
handler function
Source:
Returns:
Type
HttpServerResponse

end(chunk, enc)

Same as HttpServerResponse#end but writes a String with the specified encoding before ending the response.
Parameters:
Name Type Description
chunk string the string to write before ending the response
enc string the encoding to use
Source:

ended() → {boolean}

Source:
Returns:
  • has the response already ended?
  • Type
    boolean

exceptionHandler(handler) → {HttpServerResponse}

Parameters:
Name Type Description
handler function
Source:
Returns:
Type
HttpServerResponse

getStatusCode() → {number}

Source:
Returns:
  • the HTTP status code of the response. The default is 200 representing OK.
  • Type
    number

getStatusMessage() → {string}

Source:
Returns:
  • the HTTP status message of the response. If this is not specified a default value will be used depending on what HttpServerResponse#setStatusCode has been set to.
  • Type
    string

headers() → {MultiMap}

Source:
Returns:
  • The HTTP headers
  • Type
    MultiMap

headersEndHandler(handler) → {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. The handler will be passed a future, when you've completed the work you want to do you should complete (or fail) the future. This can be done after the handler has returned.

Parameters:
Name Type Description
handler function the handler
Source:
Returns:
a reference to this, so the API can be used fluently
Type
HttpServerResponse

headWritten() → {boolean}

Source:
Returns:
  • have the headers for the response already been written?
  • Type
    boolean

isChunked() → {boolean}

Source:
Returns:
  • is the response chunked?
  • Type
    boolean

putHeader(name, value) → {HttpServerResponse}

Put an HTTP header
Parameters:
Name Type Description
name string the header name
value string the header value.
Source:
Returns:
a reference to this, so the API can be used fluently
Type
HttpServerResponse

putTrailer(name, value) → {HttpServerResponse}

Put an HTTP trailer
Parameters:
Name Type Description
name string the trailer name
value string the trailer value
Source:
Returns:
a reference to this, so the API can be used fluently
Type
HttpServerResponse

sendFile(filename, resultHandler) → {HttpServerResponse}

Like HttpServerResponse#sendFile but providing a handler which will be notified once the file has been completely written to the wire.
Parameters:
Name Type Description
filename string path to the file to serve
resultHandler function handler that will be called on completion
Source:
Returns:
a reference to this, so the API can be used fluently
Type
HttpServerResponse

setChunked(chunked) → {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.

Parameters:
Name Type Description
chunked boolean
Source:
Returns:
a reference to this, so the API can be used fluently
Type
HttpServerResponse

setStatusCode(statusCode) → {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.
Parameters:
Name Type Description
statusCode number
Source:
Returns:
a reference to this, so the API can be used fluently
Type
HttpServerResponse

setStatusMessage(statusMessage) → {HttpServerResponse}

Set the status message
Parameters:
Name Type Description
statusMessage string
Source:
Returns:
a reference to this, so the API can be used fluently
Type
HttpServerResponse

setWriteQueueMaxSize(maxSize) → {HttpServerResponse}

Parameters:
Name Type Description
maxSize number
Source:
Returns:
Type
HttpServerResponse

trailers() → {MultiMap}

Source:
Returns:
  • The HTTP trailers
  • Type
    MultiMap

write(chunk, enc) → {HttpServerResponse}

Write a to the response body, encoded using the encoding enc.
Parameters:
Name Type Description
chunk string the string to write
enc string the encoding to use
Source:
Returns:
a reference to this, so the API can be used fluently
Type
HttpServerResponse

writeQueueFull() → {boolean}

This will return true if there are more bytes in the write queue than the value set using HttpServerResponse#setWriteQueueMaxSize
Source:
Returns:
true if write queue is full
Type
boolean