Package-level declarations

Types

Link copied to clipboard
open external class Agent : EventEmitter

An Agent is responsible for managing connection persistence and reuse for HTTP clients. It maintains a queue of pending requests for a given host and port, reusing a single socket connection for each until the queue is empty, at which time the socket is either destroyed or put into a pool where it is kept to be used again for requests to the same host and port. Whether it is destroyed or pooled depends on the keepAlive option.

Link copied to clipboard
external interface AgentOptions : TcpSocketConnectOpts
Link copied to clipboard
sealed external interface AgentOptionsScheduling
Link copied to clipboard

This object is created internally and returned from {@link request}. It represents an in-progress request whose header has already been queued. The header is still mutable using the setHeader(name, value), getHeader(name), removeHeader(name) API. The actual header will be sent along with the first data chunk or when calling request.end().

Link copied to clipboard
sealed external interface ClientRequestArgs
Link copied to clipboard
sealed external interface ClientRequestEvent
Link copied to clipboard
sealed external interface HttpStatusCodes
Link copied to clipboard
external interface IncomingHttpHeaders : Record<String, Any>
Link copied to clipboard
open external class IncomingMessage : Readable

An IncomingMessage object is created by {@link Server} or {@link ClientRequest} and passed as the first argument to the 'request' and 'response' event respectively. It may be used to access response status, headers, and data.

Link copied to clipboard
sealed external interface InformationEvent
Link copied to clipboard
Link copied to clipboard
sealed external interface OutgoingHttpHeaders : Record<String, OutgoingHttpHeader>
Link copied to clipboard

This class serves as the parent class of {@link ClientRequest} and {@link ServerResponse}. It is an abstract outgoing message from the perspective of the participants of an HTTP transaction.

Link copied to clipboard
typealias RequestListener<Request, Response> = (req: Request, res: Response) -> Unit
Link copied to clipboard
external interface RequestOptions : ClientRequestArgs
Link copied to clipboard
Link copied to clipboard
sealed external interface ServerEvent
Link copied to clipboard
Link copied to clipboard

This object is created internally by an HTTP server, not by the user. It is passed as the second parameter to the 'request' event.

Properties

Link copied to clipboard
external var globalAgent: Agent

Global instance of Agent which is used as the default for all HTTP client requests. Diverges from a default Agent configuration by having keepAlive enabled and a timeout of 5 seconds.

Link copied to clipboard
external val maxHeaderSize: Double

Read-only property specifying the maximum allowed size of HTTP headers in bytes. Defaults to 16KB. Configurable using the --max-http-header-size CLI option.

Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
external fun <Request : IncomingMessage, Response : ServerResponse<*>> createServer(requestListener: RequestListener<Request, Response> = definedExternally): Server<Request, Response>

Returns a new instance of {@link Server}.

external fun <Request : IncomingMessage, Response : ServerResponse<*>> createServer(options: ServerOptions<Request, Response>, requestListener: RequestListener<Request, Response> = definedExternally): Server<Request, Response>
Link copied to clipboard
external fun get(options: String, callback: (res: IncomingMessage) -> Unit = definedExternally): ClientRequest
external fun get(options: RequestOptions, callback: (res: IncomingMessage) -> Unit = definedExternally): ClientRequest
external fun get(options: URL, callback: (res: IncomingMessage) -> Unit = definedExternally): ClientRequest

Since most requests are GET requests without bodies, Node.js provides this convenience method. The only difference between this method and {@link request} is that it sets the method to GET by default and calls req.end() automatically. The callback must take care to consume the response data for reasons stated in {@link ClientRequest} section.

external fun get(url: String, options: RequestOptions, callback: (res: IncomingMessage) -> Unit = definedExternally): ClientRequest
external fun get(url: URL, options: RequestOptions, callback: (res: IncomingMessage) -> Unit = definedExternally): ClientRequest
Link copied to clipboard
external fun request(options: String, callback: (res: IncomingMessage) -> Unit = definedExternally): ClientRequest
external fun request(options: RequestOptions, callback: (res: IncomingMessage) -> Unit = definedExternally): ClientRequest
external fun request(options: URL, callback: (res: IncomingMessage) -> Unit = definedExternally): ClientRequest

options in socket.connect() are also supported.

external fun request(url: String, options: RequestOptions, callback: (res: IncomingMessage) -> Unit = definedExternally): ClientRequest
external fun request(url: URL, options: RequestOptions, callback: (res: IncomingMessage) -> Unit = definedExternally): ClientRequest
Link copied to clipboard
external fun setMaxIdleHTTPParsers(max: Number)

Set the maximum number of idle HTTP parsers.

Link copied to clipboard
external fun validateHeaderName(name: String)

Performs the low-level validations on the provided name that are done when res.setHeader(name, value) is called.

Link copied to clipboard
external fun validateHeaderValue(name: String, value: String)

Performs the low-level validations on the provided value that are done when res.setHeader(name, value) is called.