UNPKG

@dynatrace/runtime-simulator

Version:

The Dynatrace JavaScript runtime simulator.

1,150 lines 77.9 kB
/** * The `http` module contains HTTP client and server functionality (only client functions are supported by the Dynatrace JavaScript Runtime). You can import this module with the following code: * * ```js * const http = require('http'); * ``` * * The HTTP interfaces in Node.js are designed to support many features * of the protocol which have been traditionally difficult to use. * In particular, large, possibly chunk-encoded, messages. The interface is * careful to never buffer entire requests or responses, so the * user is able to stream data. * * HTTP message headers are represented by an object like this: * * ```js * { 'content-length': '123', * 'content-type': 'text/plain', * 'connection': 'keep-alive', * 'host': 'example.com', * 'accept': '*' } * ``` * * Keys are lowercased. Values are not modified. * * In order to support the full spectrum of possible HTTP applications, the Node.js * HTTP API is very low-level. It deals with stream handling and message * parsing only. It parses a message into headers and body but it does not * parse the actual headers or the body. * * See `message.headers` for details on how duplicate headers are handled. * * The raw headers as they were received are retained in the `rawHeaders` property, which is an array of `[key, value, key2, value2, ...]`. For * example, the previous message header object might have a `rawHeaders` list like the following: * * ```js * [ 'ConTent-Length', '123456', * 'content-LENGTH', '123', * 'content-type', 'text/plain', * 'CONNECTION', 'keep-alive', * 'Host', 'example.com', * 'accepT', '*' ] * ``` * @see [source](https://github.com/nodejs/node/blob/v18.0.0/lib/http.js) */ declare module 'http' { import * as stream from 'node:stream'; import { URL } from 'node:url'; import { TcpSocketConnectOpts, Socket, // DT-DISABLED // Server as NetServer, LookupFunction, } from 'node:net'; // incoming headers will never contain number interface IncomingHttpHeaders extends NodeJS.Dict<string | string[]> { accept?: string | undefined; 'accept-language'?: string | undefined; 'accept-patch'?: string | undefined; 'accept-ranges'?: string | undefined; 'access-control-allow-credentials'?: string | undefined; 'access-control-allow-headers'?: string | undefined; 'access-control-allow-methods'?: string | undefined; 'access-control-allow-origin'?: string | undefined; 'access-control-expose-headers'?: string | undefined; 'access-control-max-age'?: string | undefined; 'access-control-request-headers'?: string | undefined; 'access-control-request-method'?: string | undefined; age?: string | undefined; allow?: string | undefined; 'alt-svc'?: string | undefined; authorization?: string | undefined; 'cache-control'?: string | undefined; connection?: string | undefined; 'content-disposition'?: string | undefined; 'content-encoding'?: string | undefined; 'content-language'?: string | undefined; 'content-length'?: string | undefined; 'content-location'?: string | undefined; 'content-range'?: string | undefined; 'content-type'?: string | undefined; cookie?: string | undefined; date?: string | undefined; etag?: string | undefined; expect?: string | undefined; expires?: string | undefined; forwarded?: string | undefined; from?: string | undefined; host?: string | undefined; 'if-match'?: string | undefined; 'if-modified-since'?: string | undefined; 'if-none-match'?: string | undefined; 'if-unmodified-since'?: string | undefined; 'last-modified'?: string | undefined; location?: string | undefined; origin?: string | undefined; pragma?: string | undefined; 'proxy-authenticate'?: string | undefined; 'proxy-authorization'?: string | undefined; 'public-key-pins'?: string | undefined; range?: string | undefined; referer?: string | undefined; 'retry-after'?: string | undefined; 'sec-websocket-accept'?: string | undefined; 'sec-websocket-extensions'?: string | undefined; 'sec-websocket-key'?: string | undefined; 'sec-websocket-protocol'?: string | undefined; 'sec-websocket-version'?: string | undefined; 'set-cookie'?: string[] | undefined; 'strict-transport-security'?: string | undefined; tk?: string | undefined; trailer?: string | undefined; 'transfer-encoding'?: string | undefined; upgrade?: string | undefined; 'user-agent'?: string | undefined; vary?: string | undefined; via?: string | undefined; warning?: string | undefined; 'www-authenticate'?: string | undefined; } // outgoing headers allows numbers (as they are converted internally to strings) type OutgoingHttpHeader = number | string | string[]; interface OutgoingHttpHeaders extends NodeJS.Dict<OutgoingHttpHeader> {} interface ClientRequestArgs { signal?: AbortSignal | undefined; protocol?: string | null | undefined; host?: string | null | undefined; hostname?: string | null | undefined; family?: number | undefined; port?: number | string | null | undefined; defaultPort?: number | string | undefined; localAddress?: string | undefined; socketPath?: string | undefined; /** * @default 8192 */ maxHeaderSize?: number | undefined; method?: string | undefined; path?: string | null | undefined; headers?: OutgoingHttpHeaders | undefined; auth?: string | null | undefined; agent?: Agent | boolean | undefined; _defaultAgent?: Agent | undefined; timeout?: number | undefined; setHost?: boolean | undefined; // https://github.com/nodejs/node/blob/master/lib/_http_client.js#L278 createConnection?: | (( options: ClientRequestArgs, oncreate: (err: Error, socket: Socket) => void, ) => Socket) | undefined; lookup?: LookupFunction | undefined; } // DT-disabled // interface ServerOptions< // DT-disabled // Request extends typeof IncomingMessage = typeof IncomingMessage, // DT-disabled // Response extends typeof ServerResponse = typeof ServerResponse, // DT-disabled // > { // DT-disabled // IncomingMessage?: Request | undefined; // DT-disabled // ServerResponse?: Response | undefined; // DT-disabled // /** // DT-disabled // * Optionally overrides the value of // DT-disabled // * `--max-http-header-size` for requests received by this server, i.e. // DT-disabled // * the maximum length of request headers in bytes. // DT-disabled // * @default 8192 // DT-disabled // */ // DT-disabled // maxHeaderSize?: number | undefined; // DT-disabled // /** // DT-disabled // * Use an insecure HTTP parser that accepts invalid HTTP headers when true. // DT-disabled // * Using the insecure parser should be avoided. // DT-disabled // * See --insecure-http-parser for more information. // DT-disabled // * @default false // DT-disabled // */ // DT-disabled // insecureHTTPParser?: boolean | undefined; // DT-disabled // /** // DT-disabled // * If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received. // DT-disabled // * @default false // DT-disabled // * @since v16.5.0 // DT-disabled // */ // DT-disabled // noDelay?: boolean | undefined; // DT-disabled // /** // DT-disabled // * If set to `true`, it enables keep-alive functionality on the socket immediately after a new incoming connection is received, // DT-disabled // * similarly on what is done in `socket.setKeepAlive([enable][, initialDelay])`. // DT-disabled // * @default false // DT-disabled // * @since v16.5.0 // DT-disabled // */ // DT-disabled // keepAlive?: boolean | undefined; // DT-disabled // /** // DT-disabled // * If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket. // DT-disabled // * @default 0 // DT-disabled // * @since v16.5.0 // DT-disabled // */ // DT-disabled // keepAliveInitialDelay?: number | undefined; // DT-disabled // } // DT-disabled // type RequestListener< // DT-disabled // Request extends typeof IncomingMessage = typeof IncomingMessage, // DT-disabled // Response extends typeof ServerResponse = typeof ServerResponse, // DT-disabled // > = ( // DT-disabled // req: InstanceType<Request>, // DT-disabled // res: InstanceType<Response> & { req: InstanceType<Request> }, // DT-disabled // ) => void; // DT-disabled // /** // DT-disabled // * @since v0.1.17 // DT-disabled // */ // DT-disabled // class Server< // DT-disabled // Request extends typeof IncomingMessage = typeof IncomingMessage, // DT-disabled // Response extends typeof ServerResponse = typeof ServerResponse, // DT-disabled // > extends NetServer { // DT-disabled // constructor(requestListener?: RequestListener<Request, Response>); // DT-disabled // constructor( // DT-disabled // options: ServerOptions<Request, Response>, // DT-disabled // requestListener?: RequestListener<Request, Response>, // DT-disabled // ); // DT-disabled // /** // DT-disabled // * Sets the timeout value for sockets, and emits a `'timeout'` event on // DT-disabled // * the Server object, passing the socket as an argument, if a timeout // DT-disabled // * occurs. // DT-disabled // * // DT-disabled // * If there is a `'timeout'` event listener on the Server object, then it // DT-disabled // * will be called with the timed-out socket as an argument. // DT-disabled // * // DT-disabled // * By default, the Server does not timeout sockets. However, if a callback // DT-disabled // * is assigned to the Server's `'timeout'` event, timeouts must be handled // DT-disabled // * explicitly. // DT-disabled // * @since v0.9.12 // DT-disabled // * @param [msecs=0 (no timeout)] // DT-disabled // */ // DT-disabled // setTimeout(msecs?: number, callback?: () => void): this; // DT-disabled // setTimeout(callback: () => void): this; // DT-disabled // /** // DT-disabled // * Limits maximum incoming headers count. If set to 0, no limit will be applied. // DT-disabled // * @since v0.7.0 // DT-disabled // */ // DT-disabled // maxHeadersCount: number | null; // DT-disabled // /** // DT-disabled // * The maximum number of requests socket can handle // DT-disabled // * before closing keep alive connection. // DT-disabled // * // DT-disabled // * A value of `0` will disable the limit. // DT-disabled // * // DT-disabled // * When the limit is reached it will set the `Connection` header value to `close`, // DT-disabled // * but will not actually close the connection, subsequent requests sent // DT-disabled // * after the limit is reached will get `503 Service Unavailable` as a response. // DT-disabled // * @since v16.10.0 // DT-disabled // */ // DT-disabled // maxRequestsPerSocket: number | null; // DT-disabled // /** // DT-disabled // * The number of milliseconds of inactivity before a socket is presumed // DT-disabled // * to have timed out. // DT-disabled // * // DT-disabled // * A value of `0` will disable the timeout behavior on incoming connections. // DT-disabled // * // DT-disabled // * The socket timeout logic is set up on connection, so changing this // DT-disabled // * value only affects new connections to the server, not any existing connections. // DT-disabled // * @since v0.9.12 // DT-disabled // */ // DT-disabled // timeout: number; // DT-disabled // /** // DT-disabled // * Limit the amount of time the parser will wait to receive the complete HTTP // DT-disabled // * headers. // DT-disabled // * // DT-disabled // * If the timeout expires, the server responds with status 408 without // DT-disabled // * forwarding the request to the request listener and then closes the connection. // DT-disabled // * // DT-disabled // * It must be set to a non-zero value (e.g. 120 seconds) to protect against // DT-disabled // * potential Denial-of-Service attacks in case the server is deployed without a // DT-disabled // * reverse proxy in front. // DT-disabled // * @since v11.3.0, v10.14.0 // DT-disabled // */ // DT-disabled // headersTimeout: number; // DT-disabled // /** // DT-disabled // * The number of milliseconds of inactivity a server needs to wait for additional // DT-disabled // * incoming data, after it has finished writing the last response, before a socket // DT-disabled // * will be destroyed. If the server receives new data before the keep-alive // DT-disabled // * timeout has fired, it will reset the regular inactivity timeout, i.e.,`server.timeout`. // DT-disabled // * // DT-disabled // * A value of `0` will disable the keep-alive timeout behavior on incoming // DT-disabled // * connections. // DT-disabled // * A value of `0` makes the http server behave similarly to Node.js versions prior // DT-disabled // * to 8.0.0, which did not have a keep-alive timeout. // DT-disabled // * // DT-disabled // * The socket timeout logic is set up on connection, so changing this value only // DT-disabled // * affects new connections to the server, not any existing connections. // DT-disabled // * @since v8.0.0 // DT-disabled // */ // DT-disabled // keepAliveTimeout: number; // DT-disabled // /** // DT-disabled // * Sets the timeout value in milliseconds for receiving the entire request from // DT-disabled // * the client. // DT-disabled // * // DT-disabled // * If the timeout expires, the server responds with status 408 without // DT-disabled // * forwarding the request to the request listener and then closes the connection. // DT-disabled // * // DT-disabled // * It must be set to a non-zero value (e.g. 120 seconds) to protect against // DT-disabled // * potential Denial-of-Service attacks in case the server is deployed without a // DT-disabled // * reverse proxy in front. // DT-disabled // * @since v14.11.0 // DT-disabled // */ // DT-disabled // requestTimeout: number; // DT-disabled // /** // DT-disabled // * Closes all connections connected to this server. // DT-disabled // * @since v18.2.0 // DT-disabled // */ // DT-disabled // closeAllConnections(): void; // DT-disabled // /** // DT-disabled // * Closes all connections connected to this server which are not sending a request or waiting for a response. // DT-disabled // * @since v18.2.0 // DT-disabled // */ // DT-disabled // closeIdleConnections(): void; // DT-disabled // addListener(event: string, listener: (...args: any[]) => void): this; // DT-disabled // addListener(event: 'close', listener: () => void): this; // DT-disabled // addListener(event: 'connection', listener: (socket: Socket) => void): this; // DT-disabled // addListener(event: 'error', listener: (err: Error) => void): this; // DT-disabled // addListener(event: 'listening', listener: () => void): this; // DT-disabled // addListener( // DT-disabled // event: 'checkContinue', // DT-disabled // listener: RequestListener<Request, Response>, // DT-disabled // ): this; // DT-disabled // addListener( // DT-disabled // event: 'checkExpectation', // DT-disabled // listener: RequestListener<Request, Response>, // DT-disabled // ): this; // DT-disabled // addListener( // DT-disabled // event: 'clientError', // DT-disabled // listener: (err: Error, socket: stream.Duplex) => void, // DT-disabled // ): this; // DT-disabled // addListener( // DT-disabled // event: 'connect', // DT-disabled // listener: ( // DT-disabled // req: InstanceType<Request>, // DT-disabled // socket: stream.Duplex, // DT-disabled // head: Buffer, // DT-disabled // ) => void, // DT-disabled // ): this; // DT-disabled // addListener( // DT-disabled // event: 'request', // DT-disabled // listener: RequestListener<Request, Response>, // DT-disabled // ): this; // DT-disabled // addListener( // DT-disabled // event: 'upgrade', // DT-disabled // listener: ( // DT-disabled // req: InstanceType<Request>, // DT-disabled // socket: stream.Duplex, // DT-disabled // head: Buffer, // DT-disabled // ) => void, // DT-disabled // ): this; // DT-disabled // emit(event: string, ...args: any[]): boolean; // DT-disabled // emit(event: 'close'): boolean; // DT-disabled // emit(event: 'connection', socket: Socket): boolean; // DT-disabled // emit(event: 'error', err: Error): boolean; // DT-disabled // emit(event: 'listening'): boolean; // DT-disabled // emit( // DT-disabled // event: 'checkContinue', // DT-disabled // req: InstanceType<Request>, // DT-disabled // res: InstanceType<Response> & { req: InstanceType<Request> }, // DT-disabled // ): boolean; // DT-disabled // emit( // DT-disabled // event: 'checkExpectation', // DT-disabled // req: InstanceType<Request>, // DT-disabled // res: InstanceType<Response> & { req: InstanceType<Request> }, // DT-disabled // ): boolean; // DT-disabled // emit(event: 'clientError', err: Error, socket: stream.Duplex): boolean; // DT-disabled // emit( // DT-disabled // event: 'connect', // DT-disabled // req: InstanceType<Request>, // DT-disabled // socket: stream.Duplex, // DT-disabled // head: Buffer, // DT-disabled // ): boolean; // DT-disabled // emit( // DT-disabled // event: 'request', // DT-disabled // req: InstanceType<Request>, // DT-disabled // res: InstanceType<Response> & { req: InstanceType<Request> }, // DT-disabled // ): boolean; // DT-disabled // emit( // DT-disabled // event: 'upgrade', // DT-disabled // req: InstanceType<Request>, // DT-disabled // socket: stream.Duplex, // DT-disabled // head: Buffer, // DT-disabled // ): boolean; // DT-disabled // on(event: string, listener: (...args: any[]) => void): this; // DT-disabled // on(event: 'close', listener: () => void): this; // DT-disabled // on(event: 'connection', listener: (socket: Socket) => void): this; // DT-disabled // on(event: 'error', listener: (err: Error) => void): this; // DT-disabled // on(event: 'listening', listener: () => void): this; // DT-disabled // on( // DT-disabled // event: 'checkContinue', // DT-disabled // listener: RequestListener<Request, Response>, // DT-disabled // ): this; // DT-disabled // on( // DT-disabled // event: 'checkExpectation', // DT-disabled // listener: RequestListener<Request, Response>, // DT-disabled // ): this; // DT-disabled // on( // DT-disabled // event: 'clientError', // DT-disabled // listener: (err: Error, socket: stream.Duplex) => void, // DT-disabled // ): this; // DT-disabled // on( // DT-disabled // event: 'connect', // DT-disabled // listener: ( // DT-disabled // req: InstanceType<Request>, // DT-disabled // socket: stream.Duplex, // DT-disabled // head: Buffer, // DT-disabled // ) => void, // DT-disabled // ): this; // DT-disabled // on(event: 'request', listener: RequestListener<Request, Response>): this; // DT-disabled // on( // DT-disabled // event: 'upgrade', // DT-disabled // listener: ( // DT-disabled // req: InstanceType<Request>, // DT-disabled // socket: stream.Duplex, // DT-disabled // head: Buffer, // DT-disabled // ) => void, // DT-disabled // ): this; // DT-disabled // once(event: string, listener: (...args: any[]) => void): this; // DT-disabled // once(event: 'close', listener: () => void): this; // DT-disabled // once(event: 'connection', listener: (socket: Socket) => void): this; // DT-disabled // once(event: 'error', listener: (err: Error) => void): this; // DT-disabled // once(event: 'listening', listener: () => void): this; // DT-disabled // once( // DT-disabled // event: 'checkContinue', // DT-disabled // listener: RequestListener<Request, Response>, // DT-disabled // ): this; // DT-disabled // once( // DT-disabled // event: 'checkExpectation', // DT-disabled // listener: RequestListener<Request, Response>, // DT-disabled // ): this; // DT-disabled // once( // DT-disabled // event: 'clientError', // DT-disabled // listener: (err: Error, socket: stream.Duplex) => void, // DT-disabled // ): this; // DT-disabled // once( // DT-disabled // event: 'connect', // DT-disabled // listener: ( // DT-disabled // req: InstanceType<Request>, // DT-disabled // socket: stream.Duplex, // DT-disabled // head: Buffer, // DT-disabled // ) => void, // DT-disabled // ): this; // DT-disabled // once(event: 'request', listener: RequestListener<Request, Response>): this; // DT-disabled // once( // DT-disabled // event: 'upgrade', // DT-disabled // listener: ( // DT-disabled // req: InstanceType<Request>, // DT-disabled // socket: stream.Duplex, // DT-disabled // head: Buffer, // DT-disabled // ) => void, // DT-disabled // ): this; // DT-disabled // prependListener(event: string, listener: (...args: any[]) => void): this; // DT-disabled // prependListener(event: 'close', listener: () => void): this; // DT-disabled // prependListener( // DT-disabled // event: 'connection', // DT-disabled // listener: (socket: Socket) => void, // DT-disabled // ): this; // DT-disabled // prependListener(event: 'error', listener: (err: Error) => void): this; // DT-disabled // prependListener(event: 'listening', listener: () => void): this; // DT-disabled // prependListener( // DT-disabled // event: 'checkContinue', // DT-disabled // listener: RequestListener<Request, Response>, // DT-disabled // ): this; // DT-disabled // prependListener( // DT-disabled // event: 'checkExpectation', // DT-disabled // listener: RequestListener<Request, Response>, // DT-disabled // ): this; // DT-disabled // prependListener( // DT-disabled // event: 'clientError', // DT-disabled // listener: (err: Error, socket: stream.Duplex) => void, // DT-disabled // ): this; // DT-disabled // prependListener( // DT-disabled // event: 'connect', // DT-disabled // listener: ( // DT-disabled // req: InstanceType<Request>, // DT-disabled // socket: stream.Duplex, // DT-disabled // head: Buffer, // DT-disabled // ) => void, // DT-disabled // ): this; // DT-disabled // prependListener( // DT-disabled // event: 'request', // DT-disabled // listener: RequestListener<Request, Response>, // DT-disabled // ): this; // DT-disabled // prependListener( // DT-disabled // event: 'upgrade', // DT-disabled // listener: ( // DT-disabled // req: InstanceType<Request>, // DT-disabled // socket: stream.Duplex, // DT-disabled // head: Buffer, // DT-disabled // ) => void, // DT-disabled // ): this; // DT-disabled // prependOnceListener( // DT-disabled // event: string, // DT-disabled // listener: (...args: any[]) => void, // DT-disabled // ): this; // DT-disabled // prependOnceListener(event: 'close', listener: () => void): this; // DT-disabled // prependOnceListener( // DT-disabled // event: 'connection', // DT-disabled // listener: (socket: Socket) => void, // DT-disabled // ): this; // DT-disabled // prependOnceListener(event: 'error', listener: (err: Error) => void): this; // DT-disabled // prependOnceListener(event: 'listening', listener: () => void): this; // DT-disabled // prependOnceListener( // DT-disabled // event: 'checkContinue', // DT-disabled // listener: RequestListener<Request, Response>, // DT-disabled // ): this; // DT-disabled // prependOnceListener( // DT-disabled // event: 'checkExpectation', // DT-disabled // listener: RequestListener<Request, Response>, // DT-disabled // ): this; // DT-disabled // prependOnceListener( // DT-disabled // event: 'clientError', // DT-disabled // listener: (err: Error, socket: stream.Duplex) => void, // DT-disabled // ): this; // DT-disabled // prependOnceListener( // DT-disabled // event: 'connect', // DT-disabled // listener: ( // DT-disabled // req: InstanceType<Request>, // DT-disabled // socket: stream.Duplex, // DT-disabled // head: Buffer, // DT-disabled // ) => void, // DT-disabled // ): this; // DT-disabled // prependOnceListener( // DT-disabled // event: 'request', // DT-disabled // listener: RequestListener<Request, Response>, // DT-disabled // ): this; // DT-disabled // prependOnceListener( // DT-disabled // event: 'upgrade', // DT-disabled // listener: ( // DT-disabled // req: InstanceType<Request>, // DT-disabled // socket: stream.Duplex, // DT-disabled // head: Buffer, // DT-disabled // ) => void, // DT-disabled // ): this; // DT-disabled // } /** * This class serves as the parent class of {@link ClientRequest} and {@link ServerResponse}. It is an abstract of outgoing message from * the perspective of the participants of HTTP transaction. * @since v0.1.17 */ class OutgoingMessage< Request extends IncomingMessage = IncomingMessage, > extends stream.Writable { readonly req: Request; chunkedEncoding: boolean; shouldKeepAlive: boolean; useChunkedEncodingByDefault: boolean; sendDate: boolean; /** * @deprecated Use `writableEnded` instead. */ finished: boolean; /** * Read-only. `true` if the headers were sent, otherwise `false`. * @since v0.9.3 */ readonly headersSent: boolean; /** * Aliases of `outgoingMessage.socket` * @since v0.3.0 * @deprecated Since v15.12.0,v14.17.1 - Use `socket` instead. */ readonly connection: Socket | null; /** * Reference to the underlying socket. Usually, users will not want to access * this property. * * After calling `outgoingMessage.end()`, this property will be nulled. * @since v0.3.0 */ readonly socket: Socket | null; constructor(); /** * Once a socket is associated with the message and is connected,`socket.setTimeout()` will be called with `msecs` as the first parameter. * @since v0.9.12 * @param callback Optional function to be called when a timeout occurs. Same as binding to the `timeout` event. */ setTimeout(msecs: number, callback?: () => void): this; /** * Sets a single header value for the header object. * @since v0.4.0 * @param name Header name * @param value Header value */ setHeader( name: string, value: number | string | ReadonlyArray<string>, ): this; /** * Gets the value of HTTP header with the given name. If such a name doesn't * exist in message, it will be `undefined`. * @since v0.4.0 * @param name Name of header */ getHeader(name: string): number | string | string[] | undefined; /** * Returns a shallow copy of the current outgoing headers. Since a shallow * copy is used, array values may be mutated without additional calls to * various header-related HTTP module methods. The keys of the returned * object are the header names and the values are the respective header * values. All header names are lowercase. * * The object returned by the `outgoingMessage.getHeaders()` method does * not prototypically inherit from the JavaScript Object. This means that * typical Object methods such as `obj.toString()`, `obj.hasOwnProperty()`, * and others are not defined and will not work. * * ```js * outgoingMessage.setHeader('Foo', 'bar'); * outgoingMessage.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']); * * const headers = outgoingMessage.getHeaders(); * // headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] } * ``` * @since v7.7.0 */ getHeaders(): OutgoingHttpHeaders; /** * Returns an array of names of headers of the outgoing outgoingMessage. All * names are lowercase. * @since v7.7.0 */ getHeaderNames(): string[]; /** * Returns `true` if the header identified by `name` is currently set in the * outgoing headers. The header name is case-insensitive. * * ```js * const hasContentType = outgoingMessage.hasHeader('content-type'); * ``` * @since v7.7.0 */ hasHeader(name: string): boolean; /** * Removes a header that is queued for implicit sending. * * ```js * outgoingMessage.removeHeader('Content-Encoding'); * ``` * @since v0.4.0 * @param name Header name */ removeHeader(name: string): void; /** * Adds HTTP trailers (headers but at the end of the message) to the message. * * Trailers are **only** be emitted if the message is chunked encoded. If not, * the trailer will be silently discarded. * * HTTP requires the `Trailer` header to be sent to emit trailers, * with a list of header fields in its value, e.g. * * ```js * message.writeHead(200, { 'Content-Type': 'text/plain', * 'Trailer': 'Content-MD5' }); * message.write(fileData); * message.addTrailers({ 'Content-MD5': '7895bf4b8828b55ceaf47747b4bca667' }); * message.end(); * ``` * * Attempting to set a header field name or value that contains invalid characters * will result in a `TypeError` being thrown. * @since v0.3.0 */ addTrailers( headers: OutgoingHttpHeaders | ReadonlyArray<[string, string]>, ): void; /** * Compulsorily flushes the message headers * * For efficiency reason, Node.js normally buffers the message headers * until `outgoingMessage.end()` is called or the first chunk of message data * is written. It then tries to pack the headers and data into a single TCP * packet. * * It is usually desired (it saves a TCP round-trip), but not when the first * data is not sent until possibly much later. `outgoingMessage.flushHeaders()`bypasses the optimization and kickstarts the request. * @since v1.6.0 */ flushHeaders(): void; } /** * This object is created internally by an HTTP server, not by the user. It is * passed as the second parameter to the `'request'` event. * @since v0.1.17 */ // DT-disabled class ServerResponse< // DT-disabled Request extends IncomingMessage = IncomingMessage, // DT-disabled > extends OutgoingMessage<Request> { // DT-disabled /** // DT-disabled * When using implicit headers (not calling `response.writeHead()` explicitly), // DT-disabled * this property controls the status code that will be sent to the client when // DT-disabled * the headers get flushed. // DT-disabled * // DT-disabled * ```js // DT-disabled * response.statusCode = 404; // DT-disabled * ``` // DT-disabled * // DT-disabled * After response header was sent to the client, this property indicates the // DT-disabled * status code which was sent out. // DT-disabled * @since v0.4.0 // DT-disabled */ // DT-disabled statusCode: number; // DT-disabled /** // DT-disabled * When using implicit headers (not calling `response.writeHead()` explicitly), // DT-disabled * this property controls the status message that will be sent to the client when // DT-disabled * the headers get flushed. If this is left as `undefined` then the standard // DT-disabled * message for the status code will be used. // DT-disabled * // DT-disabled * ```js // DT-disabled * response.statusMessage = 'Not found'; // DT-disabled * ``` // DT-disabled * // DT-disabled * After response header was sent to the client, this property indicates the // DT-disabled * status message which was sent out. // DT-disabled * @since v0.11.8 // DT-disabled */ // DT-disabled statusMessage: string; // DT-disabled constructor(req: Request); // DT-disabled assignSocket(socket: Socket): void; // DT-disabled detachSocket(socket: Socket): void; // DT-disabled /** // DT-disabled * Sends a HTTP/1.1 100 Continue message to the client, indicating that // DT-disabled * the request body should be sent. See the `'checkContinue'` event on`Server`. // DT-disabled * @since v0.3.0 // DT-disabled */ // DT-disabled writeContinue(callback?: () => void): void; // DT-disabled /** // DT-disabled * Sends a response header to the request. The status code is a 3-digit HTTP // DT-disabled * status code, like `404`. The last argument, `headers`, are the response headers. // DT-disabled * Optionally one can give a human-readable `statusMessage` as the second // DT-disabled * argument. // DT-disabled * // DT-disabled * `headers` may be an `Array` where the keys and values are in the same list. // DT-disabled * It is _not_ a list of tuples. So, the even-numbered offsets are key values, // DT-disabled * and the odd-numbered offsets are the associated values. The array is in the same // DT-disabled * format as `request.rawHeaders`. // DT-disabled * // DT-disabled * Returns a reference to the `ServerResponse`, so that calls can be chained. // DT-disabled * // DT-disabled * ```js // DT-disabled * const body = 'hello world'; // DT-disabled * response // DT-disabled * .writeHead(200, { // DT-disabled * 'Content-Length': Buffer.byteLength(body), // DT-disabled * 'Content-Type': 'text/plain' // DT-disabled * }) // DT-disabled * .end(body); // DT-disabled * ``` // DT-disabled * // DT-disabled * This method must only be called once on a message and it must // DT-disabled * be called before `response.end()` is called. // DT-disabled * // DT-disabled * If `response.write()` or `response.end()` are called before calling // DT-disabled * this, the implicit/mutable headers will be calculated and call this function. // DT-disabled * // DT-disabled * When headers have been set with `response.setHeader()`, they will be merged // DT-disabled * with any headers passed to `response.writeHead()`, with the headers passed // DT-disabled * to `response.writeHead()` given precedence. // DT-disabled * // DT-disabled * If this method is called and `response.setHeader()` has not been called, // DT-disabled * it will directly write the supplied header values onto the network channel // DT-disabled * without caching internally, and the `response.getHeader()` on the header // DT-disabled * will not yield the expected result. If progressive population of headers is // DT-disabled * desired with potential future retrieval and modification, use `response.setHeader()` instead. // DT-disabled * // DT-disabled * ```js // DT-disabled * // Returns content-type = text/plain // DT-disabled * const server = http.createServer((req, res) => { // DT-disabled * res.setHeader('Content-Type', 'text/html'); // DT-disabled * res.setHeader('X-Foo', 'bar'); // DT-disabled * res.writeHead(200, { 'Content-Type': 'text/plain' }); // DT-disabled * res.end('ok'); // DT-disabled * }); // DT-disabled * ``` // DT-disabled * // DT-disabled * `Content-Length` is given in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes. Node.js // DT-disabled * does not check whether `Content-Length` and the length of the body which has // DT-disabled * been transmitted are equal or not. // DT-disabled * // DT-disabled * Attempting to set a header field name or value that contains invalid characters // DT-disabled * will result in a `TypeError` being thrown. // DT-disabled * @since v0.1.30 // DT-disabled */ // DT-disabled writeHead( // DT-disabled statusCode: number, // DT-disabled statusMessage?: string, // DT-disabled headers?: OutgoingHttpHeaders | OutgoingHttpHeader[], // DT-disabled ): this; // DT-disabled writeHead( // DT-disabled statusCode: number, // DT-disabled headers?: OutgoingHttpHeaders | OutgoingHttpHeader[], // DT-disabled ): this; // DT-disabled /** // DT-disabled * Sends a HTTP/1.1 102 Processing message to the client, indicating that // DT-disabled * the request body should be sent. // DT-disabled * @since v10.0.0 // DT-disabled */ // DT-disabled writeProcessing(): void; // DT-disabled } interface InformationEvent { statusCode: number; statusMessage: string; httpVersion: string; httpVersionMajor: number; httpVersionMinor: number; headers: IncomingHttpHeaders; rawHeaders: string[]; } /** * 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()`. * * To get the response, add a listener for `'response'` to the request object.`'response'` will be emitted from the request object when the response * headers have been received. The `'response'` event is executed with one * argument which is an instance of {@link IncomingMessage}. * * During the `'response'` event, one can add listeners to the * response object; particularly to listen for the `'data'` event. * * If no `'response'` handler is added, then the response will be * entirely discarded. However, if a `'response'` event handler is added, * then the data from the response object **must** be consumed, either by * calling `response.read()` whenever there is a `'readable'` event, or * by adding a `'data'` handler, or by calling the `.resume()` method. * Until the data is consumed, the `'end'` event will not fire. Also, until * the data is read it will consume memory that can eventually lead to a * 'process out of memory' error. * * For backward compatibility, `res` will only emit `'error'` if there is an`'error'` listener registered. * * Node.js does not check whether Content-Length and the length of the * body which has been transmitted are equal or not. * @since v0.1.17 */ class ClientRequest extends OutgoingMessage { /** * The `request.aborted` property will be `true` if the request has * been aborted. * @since v0.11.14 * @deprecated Since v17.0.0,v16.12.0 - Check `destroyed` instead. */ aborted: boolean; /** * The request host. * @since v14.5.0, v12.19.0 */ host: string; /** * The request protocol. * @since v14.5.0, v12.19.0 */ protocol: string; /** * When sending request through a keep-alive enabled agent, the underlying socket * might be reused. But if server closes connection at unfortunate time, client * may run into a 'ECONNRESET' error. * * ```js * const http = require('http'); * * // Server has a 5 seconds keep-alive timeout by default * http * .createServer((req, res) => { * res.write('hello\n'); * res.end(); * }) * .listen(3000); * * setInterval(() => { * // Adapting a keep-alive agent * http.get('http://localhost:3000', { agent }, (res) => { * res.on('data', (data) => { * // Do nothing * }); * }); * }, 5000); // Sending request on 5s interval so it's easy to hit idle timeout * ``` * * By marking a request whether it reused socket or not, we can do * automatic error retry base on it. * * ```js * const http = require('http'); * const agent = new http.Agent({ keepAlive: true }); * * function retriableRequest() { * const req = http * .get('http://localhost:3000', { agent }, (res) => { * // ... * }) * .on('error', (err) => { * // Check if retry is needed * if (req.reusedSocket &#x26;&#x26; err.code === 'ECONNRESET') { * retriableRequest(); * } * }); * } * * retriableRequest(); * ``` * @since v13.0.0, v12.16.0 */ reusedSocket: boolean; /** * Limits maximum response headers count. If set to 0, no limit will be applied. */ maxHeadersCount: number; constructor( url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void, ); /** * The request method. * @since v0.1.97 */ method: string; /** * The request path. * @since v0.4.0 */ path: string; /** * Marks the request as aborting. Calling this will cause remaining data * in the response to be dropped and the socket to be destroyed. * @since v0.3.8 * @deprecated Since v14.1.0,v13.14.0 - Use `destroy` instead. */ abort(): void; onSocket(socket: Socket): void; /** * Once a socket is assigned to this request and is connected `socket.setTimeout()` will be called. * @since v0.5.9 * @param timeout Milliseconds before a request times out. * @param callback Optional function to be called when a timeout occurs. Same as binding to the `'timeout'` event. */ setTimeout(timeout: number, callback?: () => void): this; /** * Once a socket is assigned to this request and is connected `socket.setNoDelay()` will be called. * @since v0.5.9 */ setNoDelay(noDelay?: boolean): void; /** * Once a socket is assigned to this request and is connected `socket.setKeepAlive()` will be called. * @since v0.5.9 */ setSocketKeepAlive(enable?: boolean, initialDelay?: number): void; /** * Returns an array containing the unique names of the current outgoing raw * headers. Header names are returned with their exact casing being set. * * ```js * request.setHeader('Foo', 'bar'); * request.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']); * * const headerNames = request.getRawHeaderNames(); * // headerNames === ['Foo', 'Set-Cookie'] * ``` * @since v15.13.0, v14.17.0 */ getRawHeaderNames(): string[]; /** * @deprecated */ addListener(event: 'abort', listener: () => void): this; addListener( event: 'connect', listener: ( response: IncomingMessage, socket: Socket, head: Buffer, ) => void, ): this; addListener(event: 'continue', listener: () => void): this; addListener( event: 'information', listener: (info: InformationEvent) => void, ): this; addListener( event: 'response', listener: (response: IncomingMessage) => void, ): this; addListener(event: 'socket', listener: (socket: Socket) => void): this; addListener(event: 'timeout', listener: () => void): this; addListener( event: 'upgrade', listener: ( response: IncomingMessage, socket: Socket, head: Buffer, ) => void, ): this; addListener(event: 'close', listener: () => void): this; addListener(event: 'drain', listener: () => void): this; addListener(event: 'error', listener: (err: Error) => void): this; addListener(event: 'finish', listener: () => void): this; addListener(event: 'pipe', listener: (src: stream.Readable) => void): this; addListener( event: 'unpipe', listener: (src: stream.Readable) => void, ): this; addListener( event: string | symbol, listener: (...args: any[]) => void, ): this; /** * @deprecated */ on(event: 'abort', listener: () => void): this; on( event: 'connect', listener: ( response: IncomingMessage, socket: Socket, head: Buffer, ) => void, ): this; on(event: 'continue', listener: () => void): this; on(event: 'information', listener: (info: InformationEvent) => void): this; on(event: 'response', listener: (response: IncomingMessage) => void): this; on(event: 'socket', listener: (socket: Socket) => void): this; on(event: 'timeout', listener: () => void): this; on( event: 'upgrade', listener: ( response: IncomingMessage, socket: Socket, head: Buffer, ) => void, ): this; on(event: 'close', listener: () => void): this; on(event: 'drain', listener: () => void): this; on(event: 'error', listener: (err: Error) => void): this; on(event: 'finish', listener: () => void): this; on(event: 'pipe', listener: (src: stream.Readable) => void): this; on(event: 'unpipe', listener: (src: stream.Readable) => void): this; on(event: string | symbol, listener: (...args: any[]) => void): this; /** * @deprecated */ once(event: 'abort', listener: () => void): this; once( event: 'connect', listener: ( response: IncomingMessage, socket: Socket, head: Buffer, ) => void, ): this; once(event: 'continue', listener: () => void): this; once( event: 'information', listener: (info: InformationEvent) => void, ): this; once( event: 'response', listener: (response: IncomingMessage) => void, ): this; once(event: 'socket', listener: (socket: Socket) => void): this; once(event: 'timeout', listener: () => void): this; once( event: 'upgrade', listener: ( response: IncomingMessage, socket: Socket, head: Buffer, ) => void, ): this; once(event: 'close', listener: () => void): this; once(event: 'drain', listener: () => void): this; once(event: 'error', listener: (err: Error) => void): this; once(event: 'finish', listener: () => void): this; once(event: 'pipe', listener: (src: stream.Readable) => void): this; once(event: 'unpipe', listener: (src: stream.Readable) => void): this; once(event: string | symbol, listener: (...args: any[]) => void): this; /** * @deprecated */ prependListener(event: 'abort', listener: () => void): this; prependListener( event: 'connect', listener: ( response: IncomingMessage, socket: Socket, head: Buffer, ) => void, ): this; prependListener(event: 'continue', listener: () => void): this; prependListener( event: 'information', listener: (info: InformationEvent) => void, ): this; prependListener( event: 'response', listener: (response: IncomingMessage) => void, ): this; prependListener(event: 'socket', listener: (socket: Socket) => void): this; prependListener(event: 'timeout', listener: () => void): this; prependListener( event: 'upgrade', listener: ( response: IncomingMessage, socket: Socket, head: Buffer, ) => void, ): this; prependListener(event: 'close', listener: () => void): this; prependListener(event: 'drain', listener: () => void): this; prependListener(event: 'error', listener: (err: Error) => void): this; prependListener(event: 'finish', listener: () => void): this; prependListener( event: 'pipe', listener: (src: stream.Readable) => void, ): this; prependListener( event: 'unpipe', listener: (src: stream.Readable) => void, ): this; prependListener( event: string | symbol, listener: (...args: any[]) => void, ): this; /** * @deprecated */ prependOnceListener(event: 'abort', listener: () => void): this; prependOnceListener( event: 'connect', listener: ( response: IncomingMessage, socket: Socket, head: Buffer, ) => void, ): this; prependOnceListener(event: 'continue', listener: () => void): this; prependOnceListener( event: 'information', listener: (info: InformationEvent) => void, ): this; prependOnceListener( event: 'response', listener: (response: IncomingMessage) => void, ): this; prependOnceListener( event: 'socket', listener: (socket: Socket) => void, ): this; prependOnceListener(event: 'timeout', listener: () => void): this; prependOnceListener( event: 'upgrade', listener: ( response: Incoming