CoolFace
Apppublic

Pinsave/counterstrike

sourceHugging Faceupdated 3mo agoView on Hugging Face
1likes
http.d.ts2047 linesDownload Raw Back to node
1/**2 * To use the HTTP server and client one must import the `node:http` module.3 *4 * The HTTP interfaces in Node.js are designed to support many features5 * of the protocol which have been traditionally difficult to use.6 * In particular, large, possibly chunk-encoded, messages. The interface is7 * careful to never buffer entire requests or responses, so the8 * user is able to stream data.9 *10 * HTTP message headers are represented by an object like this:11 *12 * ```json13 * { "content-length": "123",14 *   "content-type": "text/plain",15 *   "connection": "keep-alive",16 *   "host": "example.com",17 *   "accept": "*" }18 * ```19 *20 * Keys are lowercased. Values are not modified.21 *22 * In order to support the full spectrum of possible HTTP applications, the Node.js23 * HTTP API is very low-level. It deals with stream handling and message24 * parsing only. It parses a message into headers and body but it does not25 * parse the actual headers or the body.26 *27 * See `message.headers` for details on how duplicate headers are handled.28 *29 * The raw headers as they were received are retained in the `rawHeaders` property, which is an array of `[key, value, key2, value2, ...]`. For30 * example, the previous message header object might have a `rawHeaders` list like the following:31 *32 * ```js33 * [ 'ConTent-Length', '123456',34 *   'content-LENGTH', '123',35 *   'content-type', 'text/plain',36 *   'CONNECTION', 'keep-alive',37 *   'Host', 'example.com',38 *   'accepT', '*' ]39 * ```40 * @see [source](https://github.com/nodejs/node/blob/v24.x/lib/http.js)41 */42declare module "http" {43    import * as stream from "node:stream";44    import { URL } from "node:url";45    import { LookupOptions } from "node:dns";46    import { EventEmitter } from "node:events";47    import { LookupFunction, Server as NetServer, Socket, TcpSocketConnectOpts } from "node:net";48    // incoming headers will never contain number49    interface IncomingHttpHeaders extends NodeJS.Dict<string | string[]> {50        accept?: string | undefined;51        "accept-encoding"?: string | undefined;52        "accept-language"?: string | undefined;53        "accept-patch"?: string | undefined;54        "accept-ranges"?: string | undefined;55        "access-control-allow-credentials"?: string | undefined;56        "access-control-allow-headers"?: string | undefined;57        "access-control-allow-methods"?: string | undefined;58        "access-control-allow-origin"?: string | undefined;59        "access-control-expose-headers"?: string | undefined;60        "access-control-max-age"?: string | undefined;61        "access-control-request-headers"?: string | undefined;62        "access-control-request-method"?: string | undefined;63        age?: string | undefined;64        allow?: string | undefined;65        "alt-svc"?: string | undefined;66        authorization?: string | undefined;67        "cache-control"?: string | undefined;68        connection?: string | undefined;69        "content-disposition"?: string | undefined;70        "content-encoding"?: string | undefined;71        "content-language"?: string | undefined;72        "content-length"?: string | undefined;73        "content-location"?: string | undefined;74        "content-range"?: string | undefined;75        "content-type"?: string | undefined;76        cookie?: string | undefined;77        date?: string | undefined;78        etag?: string | undefined;79        expect?: string | undefined;80        expires?: string | undefined;81        forwarded?: string | undefined;82        from?: string | undefined;83        host?: string | undefined;84        "if-match"?: string | undefined;85        "if-modified-since"?: string | undefined;86        "if-none-match"?: string | undefined;87        "if-unmodified-since"?: string | undefined;88        "last-modified"?: string | undefined;89        location?: string | undefined;90        origin?: string | undefined;91        pragma?: string | undefined;92        "proxy-authenticate"?: string | undefined;93        "proxy-authorization"?: string | undefined;94        "public-key-pins"?: string | undefined;95        range?: string | undefined;96        referer?: string | undefined;97        "retry-after"?: string | undefined;98        "sec-fetch-site"?: string | undefined;99        "sec-fetch-mode"?: string | undefined;100        "sec-fetch-user"?: string | undefined;101        "sec-fetch-dest"?: string | undefined;102        "sec-websocket-accept"?: string | undefined;103        "sec-websocket-extensions"?: string | undefined;104        "sec-websocket-key"?: string | undefined;105        "sec-websocket-protocol"?: string | undefined;106        "sec-websocket-version"?: string | undefined;107        "set-cookie"?: string[] | undefined;108        "strict-transport-security"?: string | undefined;109        tk?: string | undefined;110        trailer?: string | undefined;111        "transfer-encoding"?: string | undefined;112        upgrade?: string | undefined;113        "user-agent"?: string | undefined;114        vary?: string | undefined;115        via?: string | undefined;116        warning?: string | undefined;117        "www-authenticate"?: string | undefined;118    }119    // outgoing headers allows numbers (as they are converted internally to strings)120    type OutgoingHttpHeader = number | string | string[];121    interface OutgoingHttpHeaders extends NodeJS.Dict<OutgoingHttpHeader> {122        accept?: string | string[] | undefined;123        "accept-charset"?: string | string[] | undefined;124        "accept-encoding"?: string | string[] | undefined;125        "accept-language"?: string | string[] | undefined;126        "accept-ranges"?: string | undefined;127        "access-control-allow-credentials"?: string | undefined;128        "access-control-allow-headers"?: string | undefined;129        "access-control-allow-methods"?: string | undefined;130        "access-control-allow-origin"?: string | undefined;131        "access-control-expose-headers"?: string | undefined;132        "access-control-max-age"?: string | undefined;133        "access-control-request-headers"?: string | undefined;134        "access-control-request-method"?: string | undefined;135        age?: string | undefined;136        allow?: string | undefined;137        authorization?: string | undefined;138        "cache-control"?: string | undefined;139        "cdn-cache-control"?: string | undefined;140        connection?: string | string[] | undefined;141        "content-disposition"?: string | undefined;142        "content-encoding"?: string | undefined;143        "content-language"?: string | undefined;144        "content-length"?: string | number | undefined;145        "content-location"?: string | undefined;146        "content-range"?: string | undefined;147        "content-security-policy"?: string | undefined;148        "content-security-policy-report-only"?: string | undefined;149        "content-type"?: string | undefined;150        cookie?: string | string[] | undefined;151        dav?: string | string[] | undefined;152        dnt?: string | undefined;153        date?: string | undefined;154        etag?: string | undefined;155        expect?: string | undefined;156        expires?: string | undefined;157        forwarded?: string | undefined;158        from?: string | undefined;159        host?: string | undefined;160        "if-match"?: string | undefined;161        "if-modified-since"?: string | undefined;162        "if-none-match"?: string | undefined;163        "if-range"?: string | undefined;164        "if-unmodified-since"?: string | undefined;165        "last-modified"?: string | undefined;166        link?: string | string[] | undefined;167        location?: string | undefined;168        "max-forwards"?: string | undefined;169        origin?: string | undefined;170        pragma?: string | string[] | undefined;171        "proxy-authenticate"?: string | string[] | undefined;172        "proxy-authorization"?: string | undefined;173        "public-key-pins"?: string | undefined;174        "public-key-pins-report-only"?: string | undefined;175        range?: string | undefined;176        referer?: string | undefined;177        "referrer-policy"?: string | undefined;178        refresh?: string | undefined;179        "retry-after"?: string | undefined;180        "sec-websocket-accept"?: string | undefined;181        "sec-websocket-extensions"?: string | string[] | undefined;182        "sec-websocket-key"?: string | undefined;183        "sec-websocket-protocol"?: string | string[] | undefined;184        "sec-websocket-version"?: string | undefined;185        server?: string | undefined;186        "set-cookie"?: string | string[] | undefined;187        "strict-transport-security"?: string | undefined;188        te?: string | undefined;189        trailer?: string | undefined;190        "transfer-encoding"?: string | undefined;191        "user-agent"?: string | undefined;192        upgrade?: string | undefined;193        "upgrade-insecure-requests"?: string | undefined;194        vary?: string | undefined;195        via?: string | string[] | undefined;196        warning?: string | undefined;197        "www-authenticate"?: string | string[] | undefined;198        "x-content-type-options"?: string | undefined;199        "x-dns-prefetch-control"?: string | undefined;200        "x-frame-options"?: string | undefined;201        "x-xss-protection"?: string | undefined;202    }203    interface ClientRequestArgs {204        _defaultAgent?: Agent | undefined;205        agent?: Agent | boolean | undefined;206        auth?: string | null | undefined;207        createConnection?:208            | ((209                options: ClientRequestArgs,210                oncreate: (err: Error | null, socket: stream.Duplex) => void,211            ) => stream.Duplex | null | undefined)212            | undefined;213        defaultPort?: number | string | undefined;214        family?: number | undefined;215        headers?: OutgoingHttpHeaders | readonly string[] | undefined;216        hints?: LookupOptions["hints"];217        host?: string | null | undefined;218        hostname?: string | null | undefined;219        insecureHTTPParser?: boolean | undefined;220        localAddress?: string | undefined;221        localPort?: number | undefined;222        lookup?: LookupFunction | undefined;223        /**224         * @default 16384225         */226        maxHeaderSize?: number | undefined;227        method?: string | undefined;228        path?: string | null | undefined;229        port?: number | string | null | undefined;230        protocol?: string | null | undefined;231        setDefaultHeaders?: boolean | undefined;232        setHost?: boolean | undefined;233        signal?: AbortSignal | undefined;234        socketPath?: string | undefined;235        timeout?: number | undefined;236        uniqueHeaders?: Array<string | string[]> | undefined;237        joinDuplicateHeaders?: boolean;238    }239    interface ServerOptions<240        Request extends typeof IncomingMessage = typeof IncomingMessage,241        Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,242    > {243        /**244         * Specifies the `IncomingMessage` class to be used. Useful for extending the original `IncomingMessage`.245         */246        IncomingMessage?: Request | undefined;247        /**248         * Specifies the `ServerResponse` class to be used. Useful for extending the original `ServerResponse`.249         */250        ServerResponse?: Response | undefined;251        /**252         * Sets the timeout value in milliseconds for receiving the entire request from the client.253         * @see Server.requestTimeout for more information.254         * @default 300000255         * @since v18.0.0256         */257        requestTimeout?: number | undefined;258        /**259         * It joins the field line values of multiple headers in a request with `, ` instead of discarding the duplicates.260         * @default false261         * @since v18.14.0262         */263        joinDuplicateHeaders?: boolean;264        /**265         * The number of milliseconds of inactivity a server needs to wait for additional incoming data,266         * after it has finished writing the last response, before a socket will be destroyed.267         * @see Server.keepAliveTimeout for more information.268         * @default 5000269         * @since v18.0.0270         */271        keepAliveTimeout?: number | undefined;272        /**273         * Sets the interval value in milliseconds to check for request and headers timeout in incomplete requests.274         * @default 30000275         */276        connectionsCheckingInterval?: number | undefined;277        /**278         * Sets the timeout value in milliseconds for receiving the complete HTTP headers from the client.279         * See {@link Server.headersTimeout} for more information.280         * @default 60000281         * @since 18.0.0282         */283        headersTimeout?: number | undefined;284        /**285         * Optionally overrides all `socket`s' `readableHighWaterMark` and `writableHighWaterMark`.286         * This affects `highWaterMark` property of both `IncomingMessage` and `ServerResponse`.287         * Default: @see stream.getDefaultHighWaterMark().288         * @since v20.1.0289         */290        highWaterMark?: number | undefined;291        /**292         * Use an insecure HTTP parser that accepts invalid HTTP headers when `true`.293         * Using the insecure parser should be avoided.294         * See --insecure-http-parser for more information.295         * @default false296         */297        insecureHTTPParser?: boolean | undefined;298        /**299         * Optionally overrides the value of `--max-http-header-size` for requests received by300         * this server, i.e. the maximum length of request headers in bytes.301         * @default 16384302         * @since v13.3.0303         */304        maxHeaderSize?: number | undefined;305        /**306         * If set to `true`, it disables the use of Nagle's algorithm immediately after a new incoming connection is received.307         * @default true308         * @since v16.5.0309         */310        noDelay?: boolean | undefined;311        /**312         * If set to `true`, it forces the server to respond with a 400 (Bad Request) status code313         * to any HTTP/1.1 request message that lacks a Host header (as mandated by the specification).314         * @default true315         * @since 20.0.0316         */317        requireHostHeader?: boolean | undefined;318        /**319         * If set to `true`, it enables keep-alive functionality on the socket immediately after a new incoming connection is received,320         * similarly on what is done in `socket.setKeepAlive([enable][, initialDelay])`.321         * @default false322         * @since v16.5.0323         */324        keepAlive?: boolean | undefined;325        /**326         * If set to a positive number, it sets the initial delay before the first keepalive probe is sent on an idle socket.327         * @default 0328         * @since v16.5.0329         */330        keepAliveInitialDelay?: number | undefined;331        /**332         * A list of response headers that should be sent only once.333         * If the header's value is an array, the items will be joined using `; `.334         */335        uniqueHeaders?: Array<string | string[]> | undefined;336        /**337         * If set to `true`, an error is thrown when writing to an HTTP response which does not have a body.338         * @default false339         * @since v18.17.0, v20.2.0340         */341        rejectNonStandardBodyWrites?: boolean | undefined;342    }343    type RequestListener<344        Request extends typeof IncomingMessage = typeof IncomingMessage,345        Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,346    > = (req: InstanceType<Request>, res: InstanceType<Response> & { req: InstanceType<Request> }) => void;347    /**348     * @since v0.1.17349     */350    class Server<351        Request extends typeof IncomingMessage = typeof IncomingMessage,352        Response extends typeof ServerResponse<InstanceType<Request>> = typeof ServerResponse,353    > extends NetServer {354        constructor(requestListener?: RequestListener<Request, Response>);355        constructor(options: ServerOptions<Request, Response>, requestListener?: RequestListener<Request, Response>);356        /**357         * Sets the timeout value for sockets, and emits a `'timeout'` event on358         * the Server object, passing the socket as an argument, if a timeout359         * occurs.360         *361         * If there is a `'timeout'` event listener on the Server object, then it362         * will be called with the timed-out socket as an argument.363         *364         * By default, the Server does not timeout sockets. However, if a callback365         * is assigned to the Server's `'timeout'` event, timeouts must be handled366         * explicitly.367         * @since v0.9.12368         * @param [msecs=0 (no timeout)]369         */370        setTimeout(msecs?: number, callback?: (socket: Socket) => void): this;371        setTimeout(callback: (socket: Socket) => void): this;372        /**373         * Limits maximum incoming headers count. If set to 0, no limit will be applied.374         * @since v0.7.0375         */376        maxHeadersCount: number | null;377        /**378         * The maximum number of requests socket can handle379         * before closing keep alive connection.380         *381         * A value of `0` will disable the limit.382         *383         * When the limit is reached it will set the `Connection` header value to `close`,384         * but will not actually close the connection, subsequent requests sent385         * after the limit is reached will get `503 Service Unavailable` as a response.386         * @since v16.10.0387         */388        maxRequestsPerSocket: number | null;389        /**390         * The number of milliseconds of inactivity before a socket is presumed391         * to have timed out.392         *393         * A value of `0` will disable the timeout behavior on incoming connections.394         *395         * The socket timeout logic is set up on connection, so changing this396         * value only affects new connections to the server, not any existing connections.397         * @since v0.9.12398         */399        timeout: number;400        /**401         * Limit the amount of time the parser will wait to receive the complete HTTP402         * headers.403         *404         * If the timeout expires, the server responds with status 408 without405         * forwarding the request to the request listener and then closes the connection.406         *407         * It must be set to a non-zero value (e.g. 120 seconds) to protect against408         * potential Denial-of-Service attacks in case the server is deployed without a409         * reverse proxy in front.410         * @since v11.3.0, v10.14.0411         */412        headersTimeout: number;413        /**414         * The number of milliseconds of inactivity a server needs to wait for additional415         * incoming data, after it has finished writing the last response, before a socket416         * will be destroyed. If the server receives new data before the keep-alive417         * timeout has fired, it will reset the regular inactivity timeout, i.e., `server.timeout`.418         *419         * A value of `0` will disable the keep-alive timeout behavior on incoming420         * connections.421         * A value of `0` makes the http server behave similarly to Node.js versions prior422         * to 8.0.0, which did not have a keep-alive timeout.423         *424         * The socket timeout logic is set up on connection, so changing this value only425         * affects new connections to the server, not any existing connections.426         * @since v8.0.0427         */428        keepAliveTimeout: number;429        /**430         * Sets the timeout value in milliseconds for receiving the entire request from431         * the client.432         *433         * If the timeout expires, the server responds with status 408 without434         * forwarding the request to the request listener and then closes the connection.435         *436         * It must be set to a non-zero value (e.g. 120 seconds) to protect against437         * potential Denial-of-Service attacks in case the server is deployed without a438         * reverse proxy in front.439         * @since v14.11.0440         */441        requestTimeout: number;442        /**443         * Closes all connections connected to this server.444         * @since v18.2.0445         */446        closeAllConnections(): void;447        /**448         * Closes all connections connected to this server which are not sending a request449         * or waiting for a response.450         * @since v18.2.0451         */452        closeIdleConnections(): void;453        addListener(event: string, listener: (...args: any[]) => void): this;454        addListener(event: "close", listener: () => void): this;455        addListener(event: "connection", listener: (socket: Socket) => void): this;456        addListener(event: "error", listener: (err: Error) => void): this;457        addListener(event: "listening", listener: () => void): this;458        addListener(event: "checkContinue", listener: RequestListener<Request, Response>): this;459        addListener(event: "checkExpectation", listener: RequestListener<Request, Response>): this;460        addListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this;461        addListener(462            event: "connect",463            listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,464        ): this;465        addListener(event: "dropRequest", listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;466        addListener(event: "request", listener: RequestListener<Request, Response>): this;467        addListener(468            event: "upgrade",469            listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,470        ): this;471        emit(event: string, ...args: any[]): boolean;472        emit(event: "close"): boolean;473        emit(event: "connection", socket: Socket): boolean;474        emit(event: "error", err: Error): boolean;475        emit(event: "listening"): boolean;476        emit(477            event: "checkContinue",478            req: InstanceType<Request>,479            res: InstanceType<Response> & { req: InstanceType<Request> },480        ): boolean;481        emit(482            event: "checkExpectation",483            req: InstanceType<Request>,484            res: InstanceType<Response> & { req: InstanceType<Request> },485        ): boolean;486        emit(event: "clientError", err: Error, socket: stream.Duplex): boolean;487        emit(event: "connect", req: InstanceType<Request>, socket: stream.Duplex, head: Buffer): boolean;488        emit(event: "dropRequest", req: InstanceType<Request>, socket: stream.Duplex): boolean;489        emit(490            event: "request",491            req: InstanceType<Request>,492            res: InstanceType<Response> & { req: InstanceType<Request> },493        ): boolean;494        emit(event: "upgrade", req: InstanceType<Request>, socket: stream.Duplex, head: Buffer): boolean;495        on(event: string, listener: (...args: any[]) => void): this;496        on(event: "close", listener: () => void): this;497        on(event: "connection", listener: (socket: Socket) => void): this;498        on(event: "error", listener: (err: Error) => void): this;499        on(event: "listening", listener: () => void): this;500        on(event: "checkContinue", listener: RequestListener<Request, Response>): this;501        on(event: "checkExpectation", listener: RequestListener<Request, Response>): this;502        on(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this;503        on(event: "connect", listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;504        on(event: "dropRequest", listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;505        on(event: "request", listener: RequestListener<Request, Response>): this;506        on(event: "upgrade", listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void): this;507        once(event: string, listener: (...args: any[]) => void): this;508        once(event: "close", listener: () => void): this;509        once(event: "connection", listener: (socket: Socket) => void): this;510        once(event: "error", listener: (err: Error) => void): this;511        once(event: "listening", listener: () => void): this;512        once(event: "checkContinue", listener: RequestListener<Request, Response>): this;513        once(event: "checkExpectation", listener: RequestListener<Request, Response>): this;514        once(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this;515        once(516            event: "connect",517            listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,518        ): this;519        once(event: "dropRequest", listener: (req: InstanceType<Request>, socket: stream.Duplex) => void): this;520        once(event: "request", listener: RequestListener<Request, Response>): this;521        once(522            event: "upgrade",523            listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,524        ): this;525        prependListener(event: string, listener: (...args: any[]) => void): this;526        prependListener(event: "close", listener: () => void): this;527        prependListener(event: "connection", listener: (socket: Socket) => void): this;528        prependListener(event: "error", listener: (err: Error) => void): this;529        prependListener(event: "listening", listener: () => void): this;530        prependListener(event: "checkContinue", listener: RequestListener<Request, Response>): this;531        prependListener(event: "checkExpectation", listener: RequestListener<Request, Response>): this;532        prependListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this;533        prependListener(534            event: "connect",535            listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,536        ): this;537        prependListener(538            event: "dropRequest",539            listener: (req: InstanceType<Request>, socket: stream.Duplex) => void,540        ): this;541        prependListener(event: "request", listener: RequestListener<Request, Response>): this;542        prependListener(543            event: "upgrade",544            listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,545        ): this;546        prependOnceListener(event: string, listener: (...args: any[]) => void): this;547        prependOnceListener(event: "close", listener: () => void): this;548        prependOnceListener(event: "connection", listener: (socket: Socket) => void): this;549        prependOnceListener(event: "error", listener: (err: Error) => void): this;550        prependOnceListener(event: "listening", listener: () => void): this;551        prependOnceListener(event: "checkContinue", listener: RequestListener<Request, Response>): this;552        prependOnceListener(event: "checkExpectation", listener: RequestListener<Request, Response>): this;553        prependOnceListener(event: "clientError", listener: (err: Error, socket: stream.Duplex) => void): this;554        prependOnceListener(555            event: "connect",556            listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,557        ): this;558        prependOnceListener(559            event: "dropRequest",560            listener: (req: InstanceType<Request>, socket: stream.Duplex) => void,561        ): this;562        prependOnceListener(event: "request", listener: RequestListener<Request, Response>): this;563        prependOnceListener(564            event: "upgrade",565            listener: (req: InstanceType<Request>, socket: stream.Duplex, head: Buffer) => void,566        ): this;567    }568    /**569     * This class serves as the parent class of {@link ClientRequest} and {@link ServerResponse}. It is an abstract outgoing message from570     * the perspective of the participants of an HTTP transaction.571     * @since v0.1.17572     */573    class OutgoingMessage<Request extends IncomingMessage = IncomingMessage> extends stream.Writable {574        readonly req: Request;575        chunkedEncoding: boolean;576        shouldKeepAlive: boolean;577        useChunkedEncodingByDefault: boolean;578        sendDate: boolean;579        /**580         * @deprecated Use `writableEnded` instead.581         */582        finished: boolean;583        /**584         * Read-only. `true` if the headers were sent, otherwise `false`.585         * @since v0.9.3586         */587        readonly headersSent: boolean;588        /**589         * Alias of `outgoingMessage.socket`.590         * @since v0.3.0591         * @deprecated Since v15.12.0,v14.17.1 - Use `socket` instead.592         */593        readonly connection: Socket | null;594        /**595         * Reference to the underlying socket. Usually, users will not want to access596         * this property.597         *598         * After calling `outgoingMessage.end()`, this property will be nulled.599         * @since v0.3.0600         */601        readonly socket: Socket | null;602        constructor();603        /**604         * Once a socket is associated with the message and is connected, `socket.setTimeout()` will be called with `msecs` as the first parameter.605         * @since v0.9.12606         * @param callback Optional function to be called when a timeout occurs. Same as binding to the `timeout` event.607         */608        setTimeout(msecs: number, callback?: () => void): this;609        /**610         * Sets a single header value. If the header already exists in the to-be-sent611         * headers, its value will be replaced. Use an array of strings to send multiple612         * headers with the same name.613         * @since v0.4.0614         * @param name Header name615         * @param value Header value616         */617        setHeader(name: string, value: number | string | readonly string[]): this;618        /**619         * Sets multiple header values for implicit headers. headers must be an instance of620         * `Headers` or `Map`, if a header already exists in the to-be-sent headers, its621         * value will be replaced.622         *623         * ```js624         * const headers = new Headers({ foo: 'bar' });625         * outgoingMessage.setHeaders(headers);626         * ```627         *628         * or629         *630         * ```js631         * const headers = new Map([['foo', 'bar']]);632         * outgoingMessage.setHeaders(headers);633         * ```634         *635         * When headers have been set with `outgoingMessage.setHeaders()`, they will be636         * merged with any headers passed to `response.writeHead()`, with the headers passed637         * to `response.writeHead()` given precedence.638         *639         * ```js640         * // Returns content-type = text/plain641         * const server = http.createServer((req, res) => {642         *   const headers = new Headers({ 'Content-Type': 'text/html' });643         *   res.setHeaders(headers);644         *   res.writeHead(200, { 'Content-Type': 'text/plain' });645         *   res.end('ok');646         * });647         * ```648         *649         * @since v19.6.0, v18.15.0650         * @param name Header name651         * @param value Header value652         */653        setHeaders(headers: Headers | Map<string, number | string | readonly string[]>): this;654        /**655         * Append a single header value to the header object.656         *657         * If the value is an array, this is equivalent to calling this method multiple658         * times.659         *660         * If there were no previous values for the header, this is equivalent to calling `outgoingMessage.setHeader(name, value)`.661         *662         * Depending of the value of `options.uniqueHeaders` when the client request or the663         * server were created, this will end up in the header being sent multiple times or664         * a single time with values joined using `; `.665         * @since v18.3.0, v16.17.0666         * @param name Header name667         * @param value Header value668         */669        appendHeader(name: string, value: string | readonly string[]): this;670        /**671         * Gets the value of the HTTP header with the given name. If that header is not672         * set, the returned value will be `undefined`.673         * @since v0.4.0674         * @param name Name of header675         */676        getHeader(name: string): number | string | string[] | undefined;677        /**678         * Returns a shallow copy of the current outgoing headers. Since a shallow679         * copy is used, array values may be mutated without additional calls to680         * various header-related HTTP module methods. The keys of the returned681         * object are the header names and the values are the respective header682         * values. All header names are lowercase.683         *684         * The object returned by the `outgoingMessage.getHeaders()` method does685         * not prototypically inherit from the JavaScript `Object`. This means that686         * typical `Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`,687         * and others are not defined and will not work.688         *689         * ```js690         * outgoingMessage.setHeader('Foo', 'bar');691         * outgoingMessage.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);692         *693         * const headers = outgoingMessage.getHeaders();694         * // headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }695         * ```696         * @since v7.7.0697         */698        getHeaders(): OutgoingHttpHeaders;699        /**700         * Returns an array containing the unique names of the current outgoing headers.701         * All names are lowercase.702         * @since v7.7.0703         */704        getHeaderNames(): string[];705        /**706         * Returns `true` if the header identified by `name` is currently set in the707         * outgoing headers. The header name is case-insensitive.708         *709         * ```js710         * const hasContentType = outgoingMessage.hasHeader('content-type');711         * ```712         * @since v7.7.0713         */714        hasHeader(name: string): boolean;715        /**716         * Removes a header that is queued for implicit sending.717         *718         * ```js719         * outgoingMessage.removeHeader('Content-Encoding');720         * ```721         * @since v0.4.0722         * @param name Header name723         */724        removeHeader(name: string): void;725        /**726         * Adds HTTP trailers (headers but at the end of the message) to the message.727         *728         * Trailers will **only** be emitted if the message is chunked encoded. If not,729         * the trailers will be silently discarded.730         *731         * HTTP requires the `Trailer` header to be sent to emit trailers,732         * with a list of header field names in its value, e.g.733         *734         * ```js735         * message.writeHead(200, { 'Content-Type': 'text/plain',736         *                          'Trailer': 'Content-MD5' });737         * message.write(fileData);738         * message.addTrailers({ 'Content-MD5': '7895bf4b8828b55ceaf47747b4bca667' });739         * message.end();740         * ```741         *742         * Attempting to set a header field name or value that contains invalid characters743         * will result in a `TypeError` being thrown.744         * @since v0.3.0745         */746        addTrailers(headers: OutgoingHttpHeaders | ReadonlyArray<[string, string]>): void;747        /**748         * Flushes the message headers.749         *750         * For efficiency reason, Node.js normally buffers the message headers751         * until `outgoingMessage.end()` is called or the first chunk of message data752         * is written. It then tries to pack the headers and data into a single TCP753         * packet.754         *755         * It is usually desired (it saves a TCP round-trip), but not when the first756         * data is not sent until possibly much later. `outgoingMessage.flushHeaders()` bypasses the optimization and kickstarts the message.757         * @since v1.6.0758         */759        flushHeaders(): void;760    }761    /**762     * This object is created internally by an HTTP server, not by the user. It is763     * passed as the second parameter to the `'request'` event.764     * @since v0.1.17765     */766    class ServerResponse<Request extends IncomingMessage = IncomingMessage> extends OutgoingMessage<Request> {767        /**768         * When using implicit headers (not calling `response.writeHead()` explicitly),769         * this property controls the status code that will be sent to the client when770         * the headers get flushed.771         *772         * ```js773         * response.statusCode = 404;774         * ```775         *776         * After response header was sent to the client, this property indicates the777         * status code which was sent out.778         * @since v0.4.0779         */780        statusCode: number;781        /**782         * When using implicit headers (not calling `response.writeHead()` explicitly),783         * this property controls the status message that will be sent to the client when784         * the headers get flushed. If this is left as `undefined` then the standard785         * message for the status code will be used.786         *787         * ```js788         * response.statusMessage = 'Not found';789         * ```790         *791         * After response header was sent to the client, this property indicates the792         * status message which was sent out.793         * @since v0.11.8794         */795        statusMessage: string;796        /**797         * If set to `true`, Node.js will check whether the `Content-Length` header value and the size of the body, in bytes, are equal.798         * Mismatching the `Content-Length` header value will result799         * in an `Error` being thrown, identified by `code:``'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`.800         * @since v18.10.0, v16.18.0801         */802        strictContentLength: boolean;803        constructor(req: Request);804        assignSocket(socket: Socket): void;805        detachSocket(socket: Socket): void;806        /**807         * Sends an HTTP/1.1 100 Continue message to the client, indicating that808         * the request body should be sent. See the `'checkContinue'` event on `Server`.809         * @since v0.3.0810         */811        writeContinue(callback?: () => void): void;812        /**813         * Sends an HTTP/1.1 103 Early Hints message to the client with a Link header,814         * indicating that the user agent can preload/preconnect the linked resources.815         * The `hints` is an object containing the values of headers to be sent with816         * early hints message. The optional `callback` argument will be called when817         * the response message has been written.818         *819         * **Example**820         *821         * ```js822         * const earlyHintsLink = '</styles.css>; rel=preload; as=style';823         * response.writeEarlyHints({824         *   'link': earlyHintsLink,825         * });826         *827         * const earlyHintsLinks = [828         *   '</styles.css>; rel=preload; as=style',829         *   '</scripts.js>; rel=preload; as=script',830         * ];831         * response.writeEarlyHints({832         *   'link': earlyHintsLinks,833         *   'x-trace-id': 'id for diagnostics',834         * });835         *836         * const earlyHintsCallback = () => console.log('early hints message sent');837         * response.writeEarlyHints({838         *   'link': earlyHintsLinks,839         * }, earlyHintsCallback);840         * ```841         * @since v18.11.0842         * @param hints An object containing the values of headers843         * @param callback Will be called when the response message has been written844         */845        writeEarlyHints(hints: Record<string, string | string[]>, callback?: () => void): void;846        /**847         * Sends a response header to the request. The status code is a 3-digit HTTP848         * status code, like `404`. The last argument, `headers`, are the response headers.849         * Optionally one can give a human-readable `statusMessage` as the second850         * argument.851         *852         * `headers` may be an `Array` where the keys and values are in the same list.853         * It is _not_ a list of tuples. So, the even-numbered offsets are key values,854         * and the odd-numbered offsets are the associated values. The array is in the same855         * format as `request.rawHeaders`.856         *857         * Returns a reference to the `ServerResponse`, so that calls can be chained.858         *859         * ```js860         * const body = 'hello world';861         * response862         *   .writeHead(200, {863         *     'Content-Length': Buffer.byteLength(body),864         *     'Content-Type': 'text/plain',865         *   })866         *   .end(body);867         * ```868         *869         * This method must only be called once on a message and it must870         * be called before `response.end()` is called.871         *872         * If `response.write()` or `response.end()` are called before calling873         * this, the implicit/mutable headers will be calculated and call this function.874         *875         * When headers have been set with `response.setHeader()`, they will be merged876         * with any headers passed to `response.writeHead()`, with the headers passed877         * to `response.writeHead()` given precedence.878         *879         * If this method is called and `response.setHeader()` has not been called,880         * it will directly write the supplied header values onto the network channel881         * without caching internally, and the `response.getHeader()` on the header882         * will not yield the expected result. If progressive population of headers is883         * desired with potential future retrieval and modification, use `response.setHeader()` instead.884         *885         * ```js886         * // Returns content-type = text/plain887         * const server = http.createServer((req, res) => {888         *   res.setHeader('Content-Type', 'text/html');889         *   res.setHeader('X-Foo', 'bar');890         *   res.writeHead(200, { 'Content-Type': 'text/plain' });891         *   res.end('ok');892         * });893         * ```894         *895         * `Content-Length` is read in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes. Node.js896         * will check whether `Content-Length` and the length of the body which has897         * been transmitted are equal or not.898         *899         * Attempting to set a header field name or value that contains invalid characters900         * will result in a \[`Error`\]\[\] being thrown.901         * @since v0.1.30902         */903        writeHead(904            statusCode: number,905            statusMessage?: string,906            headers?: OutgoingHttpHeaders | OutgoingHttpHeader[],907        ): this;908        writeHead(statusCode: number, headers?: OutgoingHttpHeaders | OutgoingHttpHeader[]): this;909        /**910         * Sends a HTTP/1.1 102 Processing message to the client, indicating that911         * the request body should be sent.912         * @since v10.0.0913         */914        writeProcessing(callback?: () => void): void;915    }916    interface InformationEvent {917        statusCode: number;918        statusMessage: string;919        httpVersion: string;920        httpVersionMajor: number;921        httpVersionMinor: number;922        headers: IncomingHttpHeaders;923        rawHeaders: string[];924    }925    /**926     * This object is created internally and returned from {@link request}. It927     * represents an _in-progress_ request whose header has already been queued. The928     * header is still mutable using the `setHeader(name, value)`, `getHeader(name)`, `removeHeader(name)` API. The actual header will929     * be sent along with the first data chunk or when calling `request.end()`.930     *931     * To get the response, add a listener for `'response'` to the request object. `'response'` will be emitted from the request object when the response932     * headers have been received. The `'response'` event is executed with one933     * argument which is an instance of {@link IncomingMessage}.934     *935     * During the `'response'` event, one can add listeners to the936     * response object; particularly to listen for the `'data'` event.937     *938     * If no `'response'` handler is added, then the response will be939     * entirely discarded. However, if a `'response'` event handler is added,940     * then the data from the response object **must** be consumed, either by941     * calling `response.read()` whenever there is a `'readable'` event, or942     * by adding a `'data'` handler, or by calling the `.resume()` method.943     * Until the data is consumed, the `'end'` event will not fire. Also, until944     * the data is read it will consume memory that can eventually lead to a945     * 'process out of memory' error.946     *947     * For backward compatibility, `res` will only emit `'error'` if there is an `'error'` listener registered.948     *949     * Set `Content-Length` header to limit the response body size.950     * If `response.strictContentLength` is set to `true`, mismatching the `Content-Length` header value will result in an `Error` being thrown,951     * identified by `code:``'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`.952     *953     * `Content-Length` value should be in bytes, not characters. Use `Buffer.byteLength()` to determine the length of the body in bytes.954     * @since v0.1.17955     */956    class ClientRequest extends OutgoingMessage {957        /**958         * The `request.aborted` property will be `true` if the request has959         * been aborted.960         * @since v0.11.14961         * @deprecated Since v17.0.0, v16.12.0 - Check `destroyed` instead.962         */963        aborted: boolean;964        /**965         * The request host.966         * @since v14.5.0, v12.19.0967         */968        host: string;969        /**970         * The request protocol.971         * @since v14.5.0, v12.19.0972         */973        protocol: string;974        /**975         * When sending request through a keep-alive enabled agent, the underlying socket976         * might be reused. But if server closes connection at unfortunate time, client977         * may run into a 'ECONNRESET' error.978         *979         * ```js980         * import http from 'node:http';981         *982         * // Server has a 5 seconds keep-alive timeout by default983         * http984         *   .createServer((req, res) => {985         *     res.write('hello\n');986         *     res.end();987         *   })988         *   .listen(3000);989         *990         * setInterval(() => {991         *   // Adapting a keep-alive agent992         *   http.get('http://localhost:3000', { agent }, (res) => {993         *     res.on('data', (data) => {994         *       // Do nothing995         *     });996         *   });997         * }, 5000); // Sending request on 5s interval so it's easy to hit idle timeout998         * ```999         *1000         * By marking a request whether it reused socket or not, we can do1001         * automatic error retry base on it.1002         *1003         * ```js1004         * import http from 'node:http';1005         * const agent = new http.Agent({ keepAlive: true });1006         *1007         * function retriableRequest() {1008         *   const req = http1009         *     .get('http://localhost:3000', { agent }, (res) => {1010         *       // ...1011         *     })1012         *     .on('error', (err) => {1013         *       // Check if retry is needed1014         *       if (req.reusedSocket &#x26;&#x26; err.code === 'ECONNRESET') {1015         *         retriableRequest();1016         *       }1017         *     });1018         * }1019         *1020         * retriableRequest();1021         * ```1022         * @since v13.0.0, v12.16.01023         */1024        reusedSocket: boolean;1025        /**1026         * Limits maximum response headers count. If set to 0, no limit will be applied.1027         */1028        maxHeadersCount: number;1029        constructor(url: string | URL | ClientRequestArgs, cb?: (res: IncomingMessage) => void);1030        /**1031         * The request method.1032         * @since v0.1.971033         */1034        method: string;1035        /**1036         * The request path.1037         * @since v0.4.01038         */1039        path: string;1040        /**1041         * Marks the request as aborting. Calling this will cause remaining data1042         * in the response to be dropped and the socket to be destroyed.1043         * @since v0.3.81044         * @deprecated Since v14.1.0,v13.14.0 - Use `destroy` instead.1045         */1046        abort(): void;1047        onSocket(socket: Socket): void;1048        /**1049         * Once a socket is assigned to this request and is connected `socket.setTimeout()` will be called.1050         * @since v0.5.91051         * @param timeout Milliseconds before a request times out.1052         * @param callback Optional function to be called when a timeout occurs. Same as binding to the `'timeout'` event.1053         */1054        setTimeout(timeout: number, callback?: () => void): this;1055        /**1056         * Once a socket is assigned to this request and is connected `socket.setNoDelay()` will be called.1057         * @since v0.5.91058         */1059        setNoDelay(noDelay?: boolean): void;1060        /**1061         * Once a socket is assigned to this request and is connected `socket.setKeepAlive()` will be called.1062         * @since v0.5.91063         */1064        setSocketKeepAlive(enable?: boolean, initialDelay?: number): void;1065        /**1066         * Returns an array containing the unique names of the current outgoing raw1067         * headers. Header names are returned with their exact casing being set.1068         *1069         * ```js1070         * request.setHeader('Foo', 'bar');1071         * request.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);1072         *1073         * const headerNames = request.getRawHeaderNames();1074         * // headerNames === ['Foo', 'Set-Cookie']1075         * ```1076         * @since v15.13.0, v14.17.01077         */1078        getRawHeaderNames(): string[];1079        /**1080         * @deprecated1081         */1082        addListener(event: "abort", listener: () => void): this;1083        addListener(1084            event: "connect",1085            listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,1086        ): this;1087        addListener(event: "continue", listener: () => void): this;1088        addListener(event: "information", listener: (info: InformationEvent) => void): this;1089        addListener(event: "response", listener: (response: IncomingMessage) => void): this;1090        addListener(event: "socket", listener: (socket: Socket) => void): this;1091        addListener(event: "timeout", listener: () => void): this;1092        addListener(1093            event: "upgrade",1094            listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,1095        ): this;1096        addListener(event: "close", listener: () => void): this;1097        addListener(event: "drain", listener: () => void): this;1098        addListener(event: "error", listener: (err: Error) => void): this;1099        addListener(event: "finish", listener: () => void): this;1100        addListener(event: "pipe", listener: (src: stream.Readable) => void): this;1101        addListener(event: "unpipe", listener: (src: stream.Readable) => void): this;1102        addListener(event: string | symbol, listener: (...args: any[]) => void): this;1103        /**1104         * @deprecated1105         */1106        on(event: "abort", listener: () => void): this;1107        on(event: "connect", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;1108        on(event: "continue", listener: () => void): this;1109        on(event: "information", listener: (info: InformationEvent) => void): this;1110        on(event: "response", listener: (response: IncomingMessage) => void): this;1111        on(event: "socket", listener: (socket: Socket) => void): this;1112        on(event: "timeout", listener: () => void): this;1113        on(event: "upgrade", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;1114        on(event: "close", listener: () => void): this;1115        on(event: "drain", listener: () => void): this;1116        on(event: "error", listener: (err: Error) => void): this;1117        on(event: "finish", listener: () => void): this;1118        on(event: "pipe", listener: (src: stream.Readable) => void): this;1119        on(event: "unpipe", listener: (src: stream.Readable) => void): this;1120        on(event: string | symbol, listener: (...args: any[]) => void): this;1121        /**1122         * @deprecated1123         */1124        once(event: "abort", listener: () => void): this;1125        once(event: "connect", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;1126        once(event: "continue", listener: () => void): this;1127        once(event: "information", listener: (info: InformationEvent) => void): this;1128        once(event: "response", listener: (response: IncomingMessage) => void): this;1129        once(event: "socket", listener: (socket: Socket) => void): this;1130        once(event: "timeout", listener: () => void): this;1131        once(event: "upgrade", listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void): this;1132        once(event: "close", listener: () => void): this;1133        once(event: "drain", listener: () => void): this;1134        once(event: "error", listener: (err: Error) => void): this;1135        once(event: "finish", listener: () => void): this;1136        once(event: "pipe", listener: (src: stream.Readable) => void): this;1137        once(event: "unpipe", listener: (src: stream.Readable) => void): this;1138        once(event: string | symbol, listener: (...args: any[]) => void): this;1139        /**1140         * @deprecated1141         */1142        prependListener(event: "abort", listener: () => void): this;1143        prependListener(1144            event: "connect",1145            listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,1146        ): this;1147        prependListener(event: "continue", listener: () => void): this;1148        prependListener(event: "information", listener: (info: InformationEvent) => void): this;1149        prependListener(event: "response", listener: (response: IncomingMessage) => void): this;1150        prependListener(event: "socket", listener: (socket: Socket) => void): this;1151        prependListener(event: "timeout", listener: () => void): this;1152        prependListener(1153            event: "upgrade",1154            listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,1155        ): this;1156        prependListener(event: "close", listener: () => void): this;1157        prependListener(event: "drain", listener: () => void): this;1158        prependListener(event: "error", listener: (err: Error) => void): this;1159        prependListener(event: "finish", listener: () => void): this;1160        prependListener(event: "pipe", listener: (src: stream.Readable) => void): this;1161        prependListener(event: "unpipe", listener: (src: stream.Readable) => void): this;1162        prependListener(event: string | symbol, listener: (...args: any[]) => void): this;1163        /**1164         * @deprecated1165         */1166        prependOnceListener(event: "abort", listener: () => void): this;1167        prependOnceListener(1168            event: "connect",1169            listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,1170        ): this;1171        prependOnceListener(event: "continue", listener: () => void): this;1172        prependOnceListener(event: "information", listener: (info: InformationEvent) => void): this;1173        prependOnceListener(event: "response", listener: (response: IncomingMessage) => void): this;1174        prependOnceListener(event: "socket", listener: (socket: Socket) => void): this;1175        prependOnceListener(event: "timeout", listener: () => void): this;1176        prependOnceListener(1177            event: "upgrade",1178            listener: (response: IncomingMessage, socket: Socket, head: Buffer) => void,1179        ): this;1180        prependOnceListener(event: "close", listener: () => void): this;1181        prependOnceListener(event: "drain", listener: () => void): this;1182        prependOnceListener(event: "error", listener: (err: Error) => void): this;1183        prependOnceListener(event: "finish", listener: () => void): this;1184        prependOnceListener(event: "pipe", listener: (src: stream.Readable) => void): this;1185        prependOnceListener(event: "unpipe", listener: (src: stream.Readable) => void): this;1186        prependOnceListener(event: string | symbol, listener: (...args: any[]) => void): this;1187    }1188    /**1189     * 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 to1190     * access response1191     * status, headers, and data.1192     *1193     * Different from its `socket` value which is a subclass of `stream.Duplex`, the `IncomingMessage` itself extends `stream.Readable` and is created separately to1194     * parse and emit the incoming HTTP headers and payload, as the underlying socket1195     * may be reused multiple times in case of keep-alive.1196     * @since v0.1.171197     */1198    class IncomingMessage extends stream.Readable {1199        constructor(socket: Socket);1200        /**

Showing the first 1,200 of 2047 lines. Download the file for the rest.