# 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:
  - vertx-js/http_server_response.js, line 34

### Methods

#### bodyEndHandler(handler) → {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.

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | the handler

Source:
  - vertx-js/http_server_response.js, line 482

##### Returns:

a reference to this, so the API can be used fluently

Type
  HttpServerResponse

#### bytesWritten() → {number}

Source:
  - vertx-js/http_server_response.js, line 496

##### Returns:

the total number of bytes written for the body of the response.

Type
  number

#### close()

Close the underlying TCP connection corresponding to the request.

Source:
  - vertx-js/http_server_response.js, line 410

#### closed() → {boolean}

Source:
  - vertx-js/http_server_response.js, line 436

##### Returns:

has the underlying TCP connection corresponding to the request already been closed?

Type
  boolean

#### closeHandler(handler) → {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.

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | the handler

Source:
  - vertx-js/http_server_response.js, line 292

##### Returns:

a reference to this, so the API can be used fluently

Type
  HttpServerResponse

#### drainHandler(handler) → {HttpServerResponse}

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function |

Source:
  - vertx-js/http_server_response.js, line 112

##### 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:
  - vertx-js/http_server_response.js, line 339

#### ended() → {boolean}

Source:
  - vertx-js/http_server_response.js, line 423

##### Returns:

has the response already ended?

Type
  boolean

#### endHandler(handler) → {HttpServerResponse}

Set an end handler for the response. This will be called when the response is disposed to allow consistent cleanup of the response.

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | the handler

Source:
  - vertx-js/http_server_response.js, line 308

##### Returns:

a reference to this, so the API can be used fluently

Type
  HttpServerResponse

#### exceptionHandler(handler) → {HttpServerResponse}

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function |

Source:
  - vertx-js/http_server_response.js, line 60

##### Returns:

Type
  HttpServerResponse

#### getStatusCode() → {number}

Source:
  - vertx-js/http_server_response.js, line 126

##### Returns:

the HTTP status code of the response. The default is `200` representing `OK`.

Type
  number

#### getStatusMessage() → {string}

Source:
  - vertx-js/http_server_response.js, line 155

##### 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:
  - vertx-js/http_server_response.js, line 221

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

##### Parameters:

Name | Type | Description
--- | --- | ---
`handler` | function | the handler

Source:
  - vertx-js/http_server_response.js, line 464

##### Returns:

a reference to this, so the API can be used fluently

Type
  HttpServerResponse

#### headWritten() → {boolean}

Source:
  - vertx-js/http_server_response.js, line 449

##### Returns:

have the headers for the response already been written?

Type
  boolean

#### isChunked() → {boolean}

Source:
  - vertx-js/http_server_response.js, line 208

##### Returns:

is the response chunked?

Type
  boolean

#### push(method, host, path, headers, handler) → {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.

##### Parameters:

Name | Type | Description
--- | --- | ---
`method` | Object | the method of the promised request
`host` | string | the host of the promised request
`path` | string | the path of the promised request
`headers` | MultiMap | the headers of the promised request
`handler` | function | the handler notified when the response can be written

Source:
  - vertx-js/http_server_response.js, line 535

##### Returns:

a reference to this, so the API can be used fluently

Type
  HttpServerResponse

#### putHeader(name, value) → {HttpServerResponse}

Put an HTTP header

##### Parameters:

Name | Type | Description
--- | --- | ---
`name` | string | the header name
`value` | string | the header value.

Source:
  - vertx-js/http_server_response.js, line 239

##### 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:
  - vertx-js/http_server_response.js, line 271

##### Returns:

a reference to this, so the API can be used fluently

Type
  HttpServerResponse

#### reset(code)

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

##### Parameters:

Name | Type | Description
--- | --- | ---
`code` | number | the error code

Source:
  - vertx-js/http_server_response.js, line 580

#### sendFile(filename, offset, length, 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
`offset` | number | the offset to serve from
`length` | number | the length to serve to
`resultHandler` | function | handler that will be called on completion

Source:
  - vertx-js/http_server_response.js, line 363

##### 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:
  - vertx-js/http_server_response.js, line 194

##### 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:
  - vertx-js/http_server_response.js, line 141

##### 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:
  - vertx-js/http_server_response.js, line 169

##### Returns:

a reference to this, so the API can be used fluently

Type
  HttpServerResponse

#### setWriteQueueMaxSize(maxSize) → {HttpServerResponse}

##### Parameters:

Name | Type | Description
--- | --- | ---
`maxSize` | number |

Source:
  - vertx-js/http_server_response.js, line 98

##### Returns:

Type
  HttpServerResponse

#### streamId() → {number}

Source:
  - vertx-js/http_server_response.js, line 509

##### Returns:

the id of the stream of this response, for HTTP/1.x

Type
  number

#### trailers() → {MultiMap}

Source:
  - vertx-js/http_server_response.js, line 253

##### Returns:

The HTTP trailers

Type
  MultiMap

#### write(chunk, enc) → {HttpServerResponse}

Write a String 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:
  - vertx-js/http_server_response.js, line 78

##### Returns:

a reference to this, so the API can be used fluently

Type
  HttpServerResponse

#### 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

Source:
  - vertx-js/http_server_response.js, line 324

##### Returns:

a reference to this, so the API can be used fluently

Type
  HttpServerResponse

#### writeCustomFrame(type, flags, payload) → {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.

##### Parameters:

Name | Type | Description
--- | --- | ---
`type` | number | the 8-bit frame type
`flags` | number | the 8-bit frame flags
`payload` | Buffer | the frame payload

Source:
  - vertx-js/http_server_response.js, line 600

##### 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:
  - vertx-js/http_server_response.js, line 47

##### Returns:

true if write queue is full

Type
  boolean