Skip to content

HTTP Server Connection

The HTTP Server Connection instance represents an active connection to an HTTP server.

The route object for this connection.

route

Accepts a new stream and returns a connection instance.

accept(options)

options

socket - A TCP Server Connection instance.

TLSSocket (optional) - A TLS socket instance for HTTPS connections.

Closes the connection.

close()

Detaches the underlying TCP socket from the HTTP connection, returning control of the socket to the caller.

detach()

A TCP Server Connection instance.

Gets the route configuration for this connection.

route

A route object.

Sets the route configuration for this connection.

route = options

options

path (optional) - A string representing the URL path.

method (optional) - A string representing the HTTP method.

handler (optional) - A callback function to handle the route.

Sends an HTTP response.

respond(options)

options

status - The HTTP status code as a number.

headers (optional) - An object containing response headers.

body (optional) - The response body.

HTTP Server Connection instance