ServerResponse

HTTP~ ServerResponse

A server-side response object for handling HTTP requests.

Constructor

new ServerResponse()

Source:

Members

headersSent

True if headers were sent, false otherwise (read-only).

Source:

socket

Reference to the underlying TCP socket.

Source:

Methods

(async) end(dataopt, encodingopt)

Signals that all of the response headers and body have been sent.

Source:
Parameters:
Name Type Attributes Default Description
data string | Uint8Array <optional>

The final data chunk to be sent with the response.

encoding string <optional>
utf-8

The character encoding to use.

getHeader(name) → {string}

Reads out a header value from raw headers.

Source:
Parameters:
Name Type Description
name string

The name of the header to retrieve.

Returns:
Type:
string

The value of the requested header.

getHeaderNames() → {Array.<string>}

Returns an array containing the unique names of the current outgoing headers.

Source:
Returns:
Type:
Array.<string>

An array of strings, each representing the name of headers.

getHeaders() → {Object}

Returns a copy of the current outgoing headers.

Source:
Returns:
Type:
Object

Key-value pair corresponds to a header name and its value.

hasHeader(name) → {boolean}

Returns true if the header identified is currently set.

Source:
Parameters:
Name Type Description
name string

The name of the header to check.

Returns:
Type:
boolean

Indicating whether the specified header is set.

removeHeader(name)

Removes a header that's queued for implicit sending.

Source:
Parameters:
Name Type Description
name String

The name of the header to remove.

setHeader(name, value)

Sets a single header value for implicit headers.

Source:
Parameters:
Name Type Description
name String

The name of the header.

value String

The value to be set for the header.

(async) write(data, encodingopt)

Writes a chunk of the response body.

Source:
Parameters:
Name Type Attributes Default Description
data String | Uint8Array

The data to be written to the response body.

encoding String <optional>
utf-8

The character encoding to use.

(async) writeHead(code, messageopt, headersopt)

Sends a response header to the request.

Source:
Parameters:
Name Type Attributes Description
code number

The HTTP status code for the response.

message string <optional>

A human-readable status message corresponding to the status code.

headers Object <optional>

Additional header fields to include in the response.