{"$schema":"https://doc-kit.nodejs.org/schemas/api-doc/1.0.0.json","id":"http","path":"/http","type":"module","module":"http","title":"HTTP","introducedIn":"v0.10.0","sourceLink":{"path":"lib/http.js","url":"https://github.com/nodejs/node/blob/HEAD/lib/http.js"},"stability":{"index":"2","description":"Stable"},"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"This module, containing both a client and server, can be imported via\n`require('node:http')` (CommonJS) or `import * as http from 'node:http'` (ES module).\n\nThe HTTP interfaces in Node.js are designed to support many features\nof the protocol which have been traditionally difficult to use.\nIn particular, large, possibly chunk-encoded, messages. The interface is\ncareful to never buffer entire requests or responses, so the\nuser is able to stream data.\n\nHTTP message headers are represented by an object like this:\n\n```json\n{ \"content-length\": \"123\",\n  \"content-type\": \"text/plain\",\n  \"connection\": \"keep-alive\",\n  \"host\": \"example.com\",\n  \"accept\": \"*/*\" }\n```\n\nKeys are lowercased. Values are not modified.\n\nIn order to support the full spectrum of possible HTTP applications, the Node.js\nHTTP API is very low-level. It deals with stream handling and message\nparsing only. It parses a message into headers and body but it does not\nparse the actual headers or the body.\n\nSee [`message.headers`](#messageheaders) for details on how duplicate headers are handled.\n\nThe raw headers as they were received are retained in the `rawHeaders`\nproperty, which is an array of `[key, value, key2, value2, ...]`. For\nexample, the previous message header object might have a `rawHeaders`\nlist like the following:\n\n```json\n[ \"ConTent-Length\", \"123456\",\n  \"content-LENGTH\", \"123\",\n  \"content-type\", \"text/plain\",\n  \"CONNECTION\", \"keep-alive\",\n  \"Host\", \"example.com\",\n  \"accepT\", \"*/*\" ]\n```","summary":"This module, containing both a client and server, can be imported via `require('node:http')` (CommonJS) or `import * as http from 'node:http'` (ES module).","examples":[{"language":"json","displayName":null,"code":"{ \"content-length\": \"123\",\n  \"content-type\": \"text/plain\",\n  \"connection\": \"keep-alive\",\n  \"host\": \"example.com\",\n  \"accept\": \"*/*\" }"},{"language":"json","displayName":null,"code":"[ \"ConTent-Length\", \"123456\",\n  \"content-LENGTH\", \"123\",\n  \"content-type\", \"text/plain\",\n  \"CONNECTION\", \"keep-alive\",\n  \"Host\", \"example.com\",\n  \"accepT\", \"*/*\" ]"}],"children":[{"kind":"class","id":"class-httpagent","name":"Agent","title":"Class: `http.Agent`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":null,"description":"An `Agent` is responsible for managing connection persistence\nand reuse for HTTP clients. It maintains a queue of pending requests\nfor a given host and port, reusing a single socket connection for each\nuntil the queue is empty, at which time the socket is either destroyed\nor put into a pool where it is kept to be used again for requests to the\nsame host and port. Whether it is destroyed or pooled depends on the\n`keepAlive` [option](#new-agentoptions).\n\nPooled connections have TCP Keep-Alive enabled for them, but servers may\nstill close idle connections, in which case they will be removed from the\npool and a new connection will be made when a new HTTP request is made for\nthat host and port. Servers may also refuse to allow multiple requests\nover the same connection, in which case the connection will have to be\nremade for every request and cannot be pooled. The `Agent` will still make\nthe requests to that server, but each one will occur over a new connection.","summary":"An `Agent` is responsible for managing connection persistence and reuse for HTTP clients. It maintains a queue of pending requests for a given host and port, reusing a single socket connection for each until the queue is empty, at which time the socket is either destroyed or put into a pool where it is kept to be used again for requests to the same host and port. Whether it is destroyed or pooled depends on the `keepAlive` option.","examples":[],"children":[{"kind":"section","id":"response-ordering-with-connection-reuse","name":"Response ordering with connection reuse","title":"Response ordering with connection reuse","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"On a reused HTTP/1.1 keep-alive connection, responses are associated with\nrequests by their order on that connection. HTTP/1.1 keep-alive does not provide\nper-request response attribution beyond that ordering. Applications that require\nper-request connection isolation can use a separate `Agent`, disable keep-alive,\nor pass `agent: false`.\n\nWhen a connection is closed by the client or the server, it is removed\nfrom the pool. Any unused sockets in the pool will be unrefed so as not\nto keep the Node.js process running when there are no outstanding requests.\n(see [`socket.unref()`](net.html#socketunref)).\n\nIt is good practice, to [`destroy()`](#agentdestroy) an `Agent` instance when it is no\nlonger in use, because unused sockets consume OS resources.\n\nSockets are removed from an agent when the socket emits either\na `'close'` event or an `'agentRemove'` event. When intending to keep one\nHTTP request open for a long time without keeping it in the agent, something\nlike the following may be done:\n\n```js\nhttp.get(options, (res) => {\n  // Do stuff\n}).on('socket', (socket) => {\n  socket.emit('agentRemove');\n});\n```\n\nAn agent may also be used for an individual request. By providing\n`{agent: false}` as an option to the `http.get()` or `http.request()`\nfunctions, a one-time use `Agent` with default options will be used\nfor the client connection.\n\n`agent:false`:\n\n```js\nhttp.get({\n  hostname: 'localhost',\n  port: 80,\n  path: '/',\n  agent: false,  // Create a new agent just for this one request\n}, (res) => {\n  // Do stuff with response\n});\n```\n\nUse `agent: false` to avoid connection reuse for a request.","summary":"On a reused HTTP/1.1 keep-alive connection, responses are associated with requests by their order on that connection. HTTP/1.1 keep-alive does not provide per-request response attribution beyond that ordering. Applications that require per-request connection isolation can use a separate `Agent`, disable keep-alive, or pass `agent: false`.","examples":[{"language":"js","displayName":null,"code":"http.get(options, (res) => {\n  // Do stuff\n}).on('socket', (socket) => {\n  socket.emit('agentRemove');\n});"},{"language":"js","displayName":null,"code":"http.get({\n  hostname: 'localhost',\n  port: 80,\n  path: '/',\n  agent: false,  // Create a new agent just for this one request\n}, (res) => {\n  // Do stuff with response\n});"}],"children":[]},{"kind":"constructor","id":"new-agentoptions","name":"Agent","title":"`new Agent([options])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v24.7.0","v22.20.0"],"prUrl":"https://github.com/nodejs/node/pull/59315","commit":null,"description":"Add support for `agentKeepAliveTimeoutBuffer`."},{"versions":["v24.5.0","v22.21.0"],"prUrl":"https://github.com/nodejs/node/pull/58980","commit":null,"description":"Add support for `proxyEnv`."},{"versions":["v24.5.0","v22.21.0"],"prUrl":"https://github.com/nodejs/node/pull/58980","commit":null,"description":"Add support for `defaultPort` and `protocol`."},{"versions":["v15.6.0","v14.17.0"],"prUrl":"https://github.com/nodejs/node/pull/36685","commit":null,"description":"Change the default scheduling from 'fifo' to 'lifo'."},{"versions":["v14.5.0","v12.19.0"],"prUrl":"https://github.com/nodejs/node/pull/33617","commit":null,"description":"Add `maxTotalSockets` option to agent constructor."},{"versions":["v14.5.0","v12.20.0"],"prUrl":"https://github.com/nodejs/node/pull/33278","commit":null,"description":"Add `scheduling` option to specify the free socket scheduling strategy."}],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"Set of configurable options to set on the agent.\nCan have the following fields:","default":null,"optional":true,"rest":false,"properties":[{"name":"keepAlive","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"Keep sockets around even when there are no\noutstanding requests, so they can be used for future requests without\nhaving to reestablish a TCP connection. Not to be confused with the\n`keep-alive` value of the `Connection` header. The `Connection: keep-alive`\nheader is always sent when using an agent except when the `Connection`\nheader is explicitly specified or when the `keepAlive` and `maxSockets`\noptions are respectively set to `false` and `Infinity`, in which case\n`Connection: close` will be used.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"keepAliveMsecs","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"When using the `keepAlive` option, specifies\nthe [initial delay](net.html#socketsetkeepaliveenable-initialdelay-interval-count)\nfor TCP Keep-Alive packets. Ignored when the\n`keepAlive` option is `false` or `undefined`.","default":"1000","optional":true,"rest":false,"properties":[]},{"name":"agentKeepAliveTimeoutBuffer","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Milliseconds to subtract from\nthe server-provided `keep-alive: timeout=...` hint when determining socket\nexpiration time. This buffer helps ensure the agent closes the socket\nslightly before the server does, reducing the chance of sending a request\non a socket that’s about to be closed by the server.","default":"1000","optional":true,"rest":false,"properties":[]},{"name":"maxSockets","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Maximum number of sockets to allow per host.\nIf the same host opens multiple concurrent connections, each request\nwill use new socket until the `maxSockets` value is reached.\nIf the host attempts to open more connections than `maxSockets`,\nthe additional requests will enter into a pending request queue, and\nwill enter active connection state when an existing connection terminates.\nThis makes sure there are at most `maxSockets` active connections at\nany point in time, from a given host.","default":"Infinity","optional":true,"rest":false,"properties":[]},{"name":"maxTotalSockets","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Maximum number of sockets allowed for\nall hosts in total. Each request will use a new socket\nuntil the maximum is reached.","default":"Infinity","optional":true,"rest":false,"properties":[]},{"name":"maxFreeSockets","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Maximum number of sockets per host to leave open\nin a free state. Only relevant if `keepAlive` is set to `true`.","default":"256","optional":true,"rest":false,"properties":[]},{"name":"scheduling","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Scheduling strategy to apply when picking\nthe next free socket to use. It can be `'fifo'` or `'lifo'`.\nThe main difference between the two scheduling strategies is that `'lifo'`\nselects the most recently used socket, while `'fifo'` selects\nthe least recently used socket.\nIn case of a low rate of request per second, the `'lifo'` scheduling\nwill lower the risk of picking a socket that might have been closed\nby the server due to inactivity.\nIn case of a high rate of request per second,\nthe `'fifo'` scheduling will maximize the number of open sockets,\nwhile the `'lifo'` scheduling will keep it as low as possible.","default":"'lifo'","optional":true,"rest":false,"properties":[]},{"name":"timeout","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Socket timeout in milliseconds.\nThis will set the timeout when the socket is created.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"proxyEnv","type":{"text":"Object | undefined","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":9,"end":18}]},"description":"Environment variables for proxy configuration.\nSee [Built-in Proxy Support](#built-in-proxy-support) for details.","default":"undefined","optional":true,"rest":false,"properties":[{"name":"HTTP_PROXY","type":{"text":"string | undefined","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":9,"end":18}]},"description":"URL for the proxy server that HTTP requests should use.\nIf undefined, no proxy is used for HTTP requests.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"HTTPS_PROXY","type":{"text":"string | undefined","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":9,"end":18}]},"description":"URL for the proxy server that HTTPS requests should use.\nIf undefined, no proxy is used for HTTPS requests.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"NO_PROXY","type":{"text":"string | undefined","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":9,"end":18}]},"description":"Patterns specifying the endpoints\nthat should not be routed through a proxy.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"http_proxy","type":{"text":"string | undefined","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":9,"end":18}]},"description":"Same as `HTTP_PROXY`. If both are set, `http_proxy` takes precedence.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"https_proxy","type":{"text":"string | undefined","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":9,"end":18}]},"description":"Same as `HTTPS_PROXY`. If both are set, `https_proxy` takes precedence.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"no_proxy","type":{"text":"string | undefined","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":9,"end":18}]},"description":"Same as `NO_PROXY`. If both are set, `no_proxy` takes precedence.","default":null,"optional":false,"rest":false,"properties":[]}]},{"name":"defaultPort","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Default port to use when the port is not specified\nin requests.","default":"80","optional":true,"rest":false,"properties":[]},{"name":"protocol","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"The protocol to use for the agent.","default":"'http:'","optional":true,"rest":false,"properties":[]}]}],"returns":null},"description":"`options` in [`socket.connect()`](net.html#socketconnectoptions-connectlistener) are also supported.\n\nTo configure any of them, a custom [`http.Agent`](#class-httpagent) instance must be created.\n\n```mjs\nimport { Agent, request } from 'node:http';\nconst keepAliveAgent = new Agent({ keepAlive: true });\noptions.agent = keepAliveAgent;\nrequest(options, onResponseCallback);\n```\n\n```cjs\nconst http = require('node:http');\nconst keepAliveAgent = new http.Agent({ keepAlive: true });\noptions.agent = keepAliveAgent;\nhttp.request(options, onResponseCallback);\n```","summary":"`options` in `socket.connect()` are also supported.","examples":[{"language":"mjs","displayName":null,"code":"import { Agent, request } from 'node:http';\nconst keepAliveAgent = new Agent({ keepAlive: true });\noptions.agent = keepAliveAgent;\nrequest(options, onResponseCallback);"},{"language":"cjs","displayName":null,"code":"const http = require('node:http');\nconst keepAliveAgent = new http.Agent({ keepAlive: true });\noptions.agent = keepAliveAgent;\nhttp.request(options, onResponseCallback);"}],"children":[]},{"kind":"method","id":"agentcreateconnectionoptions-callback","name":"createConnection","title":"`agent.createConnection(options[, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"Options containing connection details. Check\n[`net.createConnection()`](net.html#netcreateconnectionoptions-connectlistener) for the format of the options. For custom agents,\nthis object is passed to the custom `createConnection` function.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"(Optional, primarily for custom agents) A function to be\ncalled by a custom `createConnection` implementation when the socket is\ncreated, especially for asynchronous operations.","default":null,"optional":true,"rest":false,"properties":[{"name":"err","type":{"text":"Error | null","links":[{"name":"Error","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error","start":0,"end":5},{"name":"null","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#null_type","start":8,"end":12}]},"description":"An error object if socket creation failed.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"socket","type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"description":"The created socket.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"description":"The created socket. This is returned by the default\nimplementation or by a custom synchronous `createConnection` implementation.\nIf a custom `createConnection` uses the `callback` for asynchronous\noperation, this return value might not be the primary way to obtain the socket."}},"description":"Produces a socket/stream to be used for HTTP requests.\n\nBy default, this function behaves identically to [`net.createConnection()`](net.html#netcreateconnectionoptions-connectlistener),\nsynchronously returning the created socket. The optional `callback` parameter in the\nsignature is **not** used by this default implementation.\n\nHowever, custom agents may override this method to provide greater flexibility,\nfor example, to create sockets asynchronously. When overriding `createConnection`:\n\n1. **Synchronous socket creation**: The overriding method can return the\n   socket/stream directly.\n2. **Asynchronous socket creation**: The overriding method can accept the `callback`\n   and pass the created socket/stream to it (e.g., `callback(null, newSocket)`).\n   If an error occurs during socket creation, it should be passed as the first\n   argument to the `callback` (e.g., `callback(err)`).\n\nThe agent will call the provided `createConnection` function with `options` and\nthis internal `callback`. The `callback` provided by the agent has a signature\nof `(err, stream)`.","summary":"Produces a socket/stream to be used for HTTP requests.","examples":[],"children":[]},{"kind":"method","id":"agentkeepsocketalivesocket","name":"keepSocketAlive","title":"`agent.keepSocketAlive(socket)`","scope":"module","overloadOf":null,"stability":null,"added":["v8.1.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"socket","type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Called when `socket` is detached from a request and could be persisted by the\n`Agent`. Default behavior is to:\n\n```js\nsocket.setKeepAlive(true, this.keepAliveMsecs);\nsocket.unref();\nreturn true;\n```\n\nThis method can be overridden by a particular `Agent` subclass. If this\nmethod returns a falsy value, the socket will be destroyed instead of persisting\nit for use with the next request.\n\nThe `socket` argument can be an instance of {net.Socket}, a subclass of\n{stream.Duplex}.","summary":"Called when `socket` is detached from a request and could be persisted by the `Agent`. Default behavior is to:","examples":[{"language":"js","displayName":null,"code":"socket.setKeepAlive(true, this.keepAliveMsecs);\nsocket.unref();\nreturn true;"}],"children":[]},{"kind":"method","id":"agentreusesocketsocket-request","name":"reuseSocket","title":"`agent.reuseSocket(socket, request)`","scope":"module","overloadOf":null,"stability":null,"added":["v8.1.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"socket","type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"request","type":{"text":"http.ClientRequest","links":[{"name":"http.ClientRequest","href":"http.html#class-httpclientrequest","start":0,"end":18}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Called when `socket` is attached to `request` after being persisted because of\nthe keep-alive options. Default behavior is to:\n\n```js\nsocket.ref();\n```\n\nThis method can be overridden by a particular `Agent` subclass.\n\nThe `socket` argument can be an instance of {net.Socket}, a subclass of\n{stream.Duplex}.","summary":"Called when `socket` is attached to `request` after being persisted because of the keep-alive options. Default behavior is to:","examples":[{"language":"js","displayName":null,"code":"socket.ref();"}],"children":[]},{"kind":"method","id":"agentdestroy","name":"destroy","title":"`agent.destroy()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Destroy any sockets that are currently in use by the agent.\n\nIt is usually not necessary to do this. However, if using an\nagent with `keepAlive` enabled, then it is best to explicitly shut down\nthe agent when it is no longer needed. Otherwise,\nsockets might stay open for quite a long time before the server\nterminates them.","summary":"Destroy any sockets that are currently in use by the agent.","examples":[],"children":[]},{"kind":"property","id":"agentfreesockets","name":"freeSockets","title":"`agent.freeSockets`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v16.0.0"],"prUrl":"https://github.com/nodejs/node/pull/36409","commit":null,"description":"The property now has a `null` prototype."}],"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"default":null,"description":"An object which contains arrays of sockets currently awaiting use by\nthe agent when `keepAlive` is enabled. Do not modify.\n\nSockets in the `freeSockets` list will be automatically destroyed and\nremoved from the array on `'timeout'`.","summary":"An object which contains arrays of sockets currently awaiting use by the agent when `keepAlive` is enabled. Do not modify.","examples":[],"children":[]},{"kind":"method","id":"agentgetnameoptions","name":"getName","title":"`agent.getName([options])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v17.7.0","v16.15.0"],"prUrl":"https://github.com/nodejs/node/pull/41906","commit":null,"description":"The `options` parameter is now optional."}],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"A set of options providing information for name generation","default":null,"optional":true,"rest":false,"properties":[{"name":"host","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"A domain name or IP address of the server to issue the\nrequest to","default":null,"optional":false,"rest":false,"properties":[]},{"name":"port","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Port of remote server","default":null,"optional":false,"rest":false,"properties":[]},{"name":"localAddress","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Local interface to bind for network connections\nwhen issuing the request","default":null,"optional":false,"rest":false,"properties":[]},{"name":"family","type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"Must be 4 or 6 if this doesn't equal `undefined`.","default":null,"optional":false,"rest":false,"properties":[]}]}],"returns":{"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"Get a unique name for a set of request options, to determine whether a\nconnection can be reused. For an HTTP agent, this returns\n`host:port:localAddress` or `host:port:localAddress:family`. For an HTTPS agent,\nthe name includes the CA, cert, ciphers, and other HTTPS/TLS-specific options\nthat determine socket reusability.","summary":"Get a unique name for a set of request options, to determine whether a connection can be reused. For an HTTP agent, this returns `host:port:localAddress` or `host:port:localAddress:family`. For an HTTPS agent, the name includes the CA, cert, ciphers, and other HTTPS/TLS-specific options that determine socket reusability.","examples":[],"children":[]},{"kind":"property","id":"agentmaxfreesockets","name":"maxFreeSockets","title":"`agent.maxFreeSockets`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.7"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"By default set to 256. For agents with `keepAlive` enabled, this\nsets the maximum number of sockets that will be left open in the free\nstate.","summary":"By default set to 256. For agents with `keepAlive` enabled, this sets the maximum number of sockets that will be left open in the free state.","examples":[],"children":[]},{"kind":"property","id":"agentmaxsockets","name":"maxSockets","title":"`agent.maxSockets`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.6"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"By default set to `Infinity`. Determines how many concurrent sockets the agent\ncan have open per origin. Origin is the returned value of [`agent.getName()`](#agentgetnameoptions).","summary":"By default set to `Infinity`. Determines how many concurrent sockets the agent can have open per origin. Origin is the returned value of `agent.getName()`.","examples":[],"children":[]},{"kind":"property","id":"agentmaxtotalsockets","name":"maxTotalSockets","title":"`agent.maxTotalSockets`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0","v12.19.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"By default set to `Infinity`. Determines how many concurrent sockets the agent\ncan have open. Unlike `maxSockets`, this parameter applies across all origins.","summary":"By default set to `Infinity`. Determines how many concurrent sockets the agent can have open. Unlike `maxSockets`, this parameter applies across all origins.","examples":[],"children":[]},{"kind":"property","id":"agentrequests","name":"requests","title":"`agent.requests`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.9"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v16.0.0"],"prUrl":"https://github.com/nodejs/node/pull/36409","commit":null,"description":"The property now has a `null` prototype."}],"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"default":null,"description":"An object which contains queues of requests that have not yet been assigned to\nsockets. Do not modify.","summary":"An object which contains queues of requests that have not yet been assigned to sockets. Do not modify.","examples":[],"children":[]},{"kind":"property","id":"agentsockets","name":"sockets","title":"`agent.sockets`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.6"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v16.0.0"],"prUrl":"https://github.com/nodejs/node/pull/36409","commit":null,"description":"The property now has a `null` prototype."}],"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"default":null,"description":"An object which contains arrays of sockets currently in use by the\nagent. Do not modify.","summary":"An object which contains arrays of sockets currently in use by the agent. Do not modify.","examples":[],"children":[]}]},{"kind":"class","id":"class-httpclientrequest","name":"ClientRequest","title":"Class: `http.ClientRequest`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.17"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":{"text":"http.OutgoingMessage","links":[{"name":"http.OutgoingMessage","href":"http.html#class-httpoutgoingmessage","start":0,"end":20}]},"description":"This object is created internally and returned from [`http.request()`](#httprequestoptions-callback). It\nrepresents an *in-progress* request whose header has already been queued. The\nheader is still mutable using the [`setHeader(name, value)`](#requestsetheadername-value),\n[`getHeader(name)`](#requestgetheadername), [`removeHeader(name)`](#requestremoveheadername) API. The actual header will\nbe sent along with the first data chunk or when calling [`request.end()`](#requestenddata-encoding-callback).\n\nTo get the response, add a listener for [`'response'`](#event-response) to the request object.\n[`'response'`](#event-response) will be emitted from the request object when the response\nheaders have been received. The [`'response'`](#event-response) event is executed with one\nargument which is an instance of [`http.IncomingMessage`](#class-httpincomingmessage).\n\nDuring the [`'response'`](#event-response) event, one can add listeners to the\nresponse object; particularly to listen for the `'data'` event.\n\nIf no [`'response'`](#event-response) handler is added, then the response will be\nentirely discarded. However, if a [`'response'`](#event-response) event handler is added,\nthen the data from the response object **must** be consumed, either by\ncalling `response.read()` whenever there is a `'readable'` event, or\nby adding a `'data'` handler, or by calling the `.resume()` method.\nUntil the data is consumed, the `'end'` event will not fire. Also, until\nthe data is read it will consume memory that can eventually lead to a\n'process out of memory' error.\n\nFor backward compatibility, `res` will only emit `'error'` if there is an\n`'error'` listener registered.\n\nSet `Content-Length` header to limit the response body size.\nIf [`response.strictContentLength`](#responsestrictcontentlength) is set to `true`, mismatching the\n`Content-Length` header value will result in an `Error` being thrown,\nidentified by `code:` [`'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`](errors.html#err_http_content_length_mismatch).\n\n`Content-Length` value should be in bytes, not characters. Use\n[`Buffer.byteLength()`](buffer.html#static-method-bufferbytelengthstring-encoding) to determine the length of the body in bytes.","summary":"This object is created internally and returned from `http.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()`.","examples":[],"children":[{"kind":"event","id":"event-abort","name":"abort","title":"Event: `'abort'`","scope":"module","overloadOf":null,"stability":{"index":"0","description":"Deprecated. Listen for the `'close'` event instead."},"added":["v1.4.1"],"deprecated":["v17.0.0","v16.12.0"],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Emitted when the request has been aborted by the client. This event is only\nemitted on the first call to `abort()`.","summary":"Emitted when the request has been aborted by the client. This event is only emitted on the first call to `abort()`.","examples":[],"children":[]},{"kind":"event","id":"event-close","name":"close","title":"Event: `'close'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Indicates that the request is completed, or its underlying connection was\nterminated prematurely (before the response completion).","summary":"Indicates that the request is completed, or its underlying connection was terminated prematurely (before the response completion).","examples":[],"children":[]},{"kind":"event","id":"event-connect","name":"connect","title":"Event: `'connect'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"response","type":{"text":"http.IncomingMessage","links":[{"name":"http.IncomingMessage","href":"http.html#class-httpincomingmessage","start":0,"end":20}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"socket","type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"head","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"description":"Emitted each time a server responds to a request with a `CONNECT` method. If\nthis event is not being listened for, clients receiving a `CONNECT` method will\nhave their connections closed.\n\nThis event is guaranteed to be passed an instance of the {net.Socket} class,\na subclass of {stream.Duplex}, unless the user specifies a socket\ntype other than {net.Socket}.\n\nA client and server pair demonstrating how to listen for the `'connect'` event:\n\n```mjs\nimport { createServer, request } from 'node:http';\nimport { connect } from 'node:net';\nimport { URL } from 'node:url';\n\n// Create an HTTP tunneling proxy\nconst proxy = createServer((req, res) => {\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('okay');\n});\nproxy.on('connect', (req, clientSocket, head) => {\n  // Connect to an origin server\n  const { port, hostname } = new URL(`http://${req.url}`);\n  const serverSocket = connect(port || 80, hostname, () => {\n    clientSocket.write('HTTP/1.1 200 Connection Established\\r\\n' +\n                    'Proxy-agent: Node.js-Proxy\\r\\n' +\n                    '\\r\\n');\n    serverSocket.write(head);\n    serverSocket.pipe(clientSocket);\n    clientSocket.pipe(serverSocket);\n  });\n});\n\n// Now that proxy is running\nproxy.listen(1337, '127.0.0.1', () => {\n\n  // Make a request to a tunneling proxy\n  const options = {\n    port: 1337,\n    host: '127.0.0.1',\n    method: 'CONNECT',\n    path: 'www.google.com:80',\n  };\n\n  const req = request(options);\n  req.end();\n\n  req.on('connect', (res, socket, head) => {\n    console.log('got connected!');\n\n    // Make a request over an HTTP tunnel\n    socket.write('GET / HTTP/1.1\\r\\n' +\n                 'Host: www.google.com:80\\r\\n' +\n                 'Connection: close\\r\\n' +\n                 '\\r\\n');\n    socket.on('data', (chunk) => {\n      console.log(chunk.toString());\n    });\n    socket.on('end', () => {\n      proxy.close();\n    });\n  });\n});\n```\n\n```cjs\nconst http = require('node:http');\nconst net = require('node:net');\nconst { URL } = require('node:url');\n\n// Create an HTTP tunneling proxy\nconst proxy = http.createServer((req, res) => {\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('okay');\n});\nproxy.on('connect', (req, clientSocket, head) => {\n  // Connect to an origin server\n  const { port, hostname } = new URL(`http://${req.url}`);\n  const serverSocket = net.connect(port || 80, hostname, () => {\n    clientSocket.write('HTTP/1.1 200 Connection Established\\r\\n' +\n                    'Proxy-agent: Node.js-Proxy\\r\\n' +\n                    '\\r\\n');\n    serverSocket.write(head);\n    serverSocket.pipe(clientSocket);\n    clientSocket.pipe(serverSocket);\n  });\n});\n\n// Now that proxy is running\nproxy.listen(1337, '127.0.0.1', () => {\n\n  // Make a request to a tunneling proxy\n  const options = {\n    port: 1337,\n    host: '127.0.0.1',\n    method: 'CONNECT',\n    path: 'www.google.com:80',\n  };\n\n  const req = http.request(options);\n  req.end();\n\n  req.on('connect', (res, socket, head) => {\n    console.log('got connected!');\n\n    // Make a request over an HTTP tunnel\n    socket.write('GET / HTTP/1.1\\r\\n' +\n                 'Host: www.google.com:80\\r\\n' +\n                 'Connection: close\\r\\n' +\n                 '\\r\\n');\n    socket.on('data', (chunk) => {\n      console.log(chunk.toString());\n    });\n    socket.on('end', () => {\n      proxy.close();\n    });\n  });\n});\n```","summary":"Emitted each time a server responds to a request with a `CONNECT` method. If this event is not being listened for, clients receiving a `CONNECT` method will have their connections closed.","examples":[{"language":"mjs","displayName":null,"code":"import { createServer, request } from 'node:http';\nimport { connect } from 'node:net';\nimport { URL } from 'node:url';\n\n// Create an HTTP tunneling proxy\nconst proxy = createServer((req, res) => {\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('okay');\n});\nproxy.on('connect', (req, clientSocket, head) => {\n  // Connect to an origin server\n  const { port, hostname } = new URL(`http://${req.url}`);\n  const serverSocket = connect(port || 80, hostname, () => {\n    clientSocket.write('HTTP/1.1 200 Connection Established\\r\\n' +\n                    'Proxy-agent: Node.js-Proxy\\r\\n' +\n                    '\\r\\n');\n    serverSocket.write(head);\n    serverSocket.pipe(clientSocket);\n    clientSocket.pipe(serverSocket);\n  });\n});\n\n// Now that proxy is running\nproxy.listen(1337, '127.0.0.1', () => {\n\n  // Make a request to a tunneling proxy\n  const options = {\n    port: 1337,\n    host: '127.0.0.1',\n    method: 'CONNECT',\n    path: 'www.google.com:80',\n  };\n\n  const req = request(options);\n  req.end();\n\n  req.on('connect', (res, socket, head) => {\n    console.log('got connected!');\n\n    // Make a request over an HTTP tunnel\n    socket.write('GET / HTTP/1.1\\r\\n' +\n                 'Host: www.google.com:80\\r\\n' +\n                 'Connection: close\\r\\n' +\n                 '\\r\\n');\n    socket.on('data', (chunk) => {\n      console.log(chunk.toString());\n    });\n    socket.on('end', () => {\n      proxy.close();\n    });\n  });\n});"},{"language":"cjs","displayName":null,"code":"const http = require('node:http');\nconst net = require('node:net');\nconst { URL } = require('node:url');\n\n// Create an HTTP tunneling proxy\nconst proxy = http.createServer((req, res) => {\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('okay');\n});\nproxy.on('connect', (req, clientSocket, head) => {\n  // Connect to an origin server\n  const { port, hostname } = new URL(`http://${req.url}`);\n  const serverSocket = net.connect(port || 80, hostname, () => {\n    clientSocket.write('HTTP/1.1 200 Connection Established\\r\\n' +\n                    'Proxy-agent: Node.js-Proxy\\r\\n' +\n                    '\\r\\n');\n    serverSocket.write(head);\n    serverSocket.pipe(clientSocket);\n    clientSocket.pipe(serverSocket);\n  });\n});\n\n// Now that proxy is running\nproxy.listen(1337, '127.0.0.1', () => {\n\n  // Make a request to a tunneling proxy\n  const options = {\n    port: 1337,\n    host: '127.0.0.1',\n    method: 'CONNECT',\n    path: 'www.google.com:80',\n  };\n\n  const req = http.request(options);\n  req.end();\n\n  req.on('connect', (res, socket, head) => {\n    console.log('got connected!');\n\n    // Make a request over an HTTP tunnel\n    socket.write('GET / HTTP/1.1\\r\\n' +\n                 'Host: www.google.com:80\\r\\n' +\n                 'Connection: close\\r\\n' +\n                 '\\r\\n');\n    socket.on('data', (chunk) => {\n      console.log(chunk.toString());\n    });\n    socket.on('end', () => {\n      proxy.close();\n    });\n  });\n});"}],"children":[]},{"kind":"event","id":"event-continue","name":"continue","title":"Event: `'continue'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.2"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Emitted when the server sends a '100 Continue' HTTP response, usually because\nthe request contained 'Expect: 100-continue'. This is an instruction that\nthe client should send the request body.","summary":"Emitted when the server sends a '100 Continue' HTTP response, usually because the request contained 'Expect: 100-continue'. This is an instruction that the client should send the request body.","examples":[],"children":[]},{"kind":"event","id":"event-finish","name":"finish","title":"Event: `'finish'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.6"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Emitted when the request has been sent. More specifically, this event is emitted\nwhen the last segment of the request headers and body have been handed off to\nthe operating system for transmission over the network. It does not imply that\nthe server has received anything yet.","summary":"Emitted when the request has been sent. More specifically, this event is emitted when the last segment of the request headers and body have been handed off to the operating system for transmission over the network. It does not imply that the server has received anything yet.","examples":[],"children":[]},{"kind":"event","id":"event-information","name":"information","title":"Event: `'information'`","scope":"module","overloadOf":null,"stability":null,"added":["v10.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"info","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[{"name":"httpVersion","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"httpVersionMajor","type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"httpVersionMinor","type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"statusCode","type":{"text":"integer","links":[{"name":"integer","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":7}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"statusMessage","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"headers","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"rawHeaders","type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}]}],"description":"Emitted when the server sends a 1xx intermediate response (excluding 101\nUpgrade). The listeners of this event will receive an object containing the\nHTTP version, status code, status message, key-value headers object,\nand array with the raw header names followed by their respective values.\n\n```mjs\nimport { request } from 'node:http';\n\nconst options = {\n  host: '127.0.0.1',\n  port: 8080,\n  path: '/length_request',\n};\n\n// Make a request\nconst req = request(options);\nreq.end();\n\nreq.on('information', (info) => {\n  console.log(`Got information prior to main response: ${info.statusCode}`);\n});\n```\n\n```cjs\nconst http = require('node:http');\n\nconst options = {\n  host: '127.0.0.1',\n  port: 8080,\n  path: '/length_request',\n};\n\n// Make a request\nconst req = http.request(options);\nreq.end();\n\nreq.on('information', (info) => {\n  console.log(`Got information prior to main response: ${info.statusCode}`);\n});\n```\n\n101 Upgrade statuses do not fire this event due to their break from the\ntraditional HTTP request/response chain, such as web sockets, in-place TLS\nupgrades, or HTTP 2.0. To be notified of 101 Upgrade notices, listen for the\n[`'upgrade'`](#event-upgrade) event instead.","summary":"Emitted when the server sends a 1xx intermediate response (excluding 101 Upgrade). The listeners of this event will receive an object containing the HTTP version, status code, status message, key-value headers object, and array with the raw header names followed by their respective values.","examples":[{"language":"mjs","displayName":null,"code":"import { request } from 'node:http';\n\nconst options = {\n  host: '127.0.0.1',\n  port: 8080,\n  path: '/length_request',\n};\n\n// Make a request\nconst req = request(options);\nreq.end();\n\nreq.on('information', (info) => {\n  console.log(`Got information prior to main response: ${info.statusCode}`);\n});"},{"language":"cjs","displayName":null,"code":"const http = require('node:http');\n\nconst options = {\n  host: '127.0.0.1',\n  port: 8080,\n  path: '/length_request',\n};\n\n// Make a request\nconst req = http.request(options);\nreq.end();\n\nreq.on('information', (info) => {\n  console.log(`Got information prior to main response: ${info.statusCode}`);\n});"}],"children":[]},{"kind":"event","id":"event-response","name":"response","title":"Event: `'response'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"response","type":{"text":"http.IncomingMessage","links":[{"name":"http.IncomingMessage","href":"http.html#class-httpincomingmessage","start":0,"end":20}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"description":"Emitted when a response is received to this request. This event is emitted only\nonce.","summary":"Emitted when a response is received to this request. This event is emitted only once.","examples":[],"children":[]},{"kind":"event","id":"event-socket","name":"socket","title":"Event: `'socket'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.3"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"socket","type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"description":"This event is guaranteed to be passed an instance of the {net.Socket} class,\na subclass of {stream.Duplex}, unless the user specifies a socket\ntype other than {net.Socket}.","summary":"This event is guaranteed to be passed an instance of the {net.Socket} class, a subclass of {stream.Duplex}, unless the user specifies a socket type other than {net.Socket}.","examples":[],"children":[]},{"kind":"event","id":"event-timeout","name":"timeout","title":"Event: `'timeout'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.8"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Emitted when the underlying socket times out from inactivity. This only notifies\nthat the socket has been idle. The request must be destroyed manually.\n\nSee also: [`request.setTimeout()`](#requestsettimeouttimeout-callback).","summary":"Emitted when the underlying socket times out from inactivity. This only notifies that the socket has been idle. The request must be destroyed manually.","examples":[],"children":[]},{"kind":"event","id":"event-upgrade","name":"upgrade","title":"Event: `'upgrade'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.94"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"response","type":{"text":"http.IncomingMessage","links":[{"name":"http.IncomingMessage","href":"http.html#class-httpincomingmessage","start":0,"end":20}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"stream","type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"head","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"description":"Emitted each time a server responds to a request with an upgrade. If this\nevent is not being listened for and the response status code is 101 Switching\nProtocols, clients receiving an upgrade header will have their connections\nclosed.\n\nThis event is guaranteed to be passed an instance of the {net.Socket} class,\na subclass of {stream.Duplex}, unless the user specifies a socket\ntype other than {net.Socket}.\n\nA client server pair demonstrating how to listen for the `'upgrade'` event.\n\n```mjs\nimport http from 'node:http';\nimport process from 'node:process';\n\n// Create an HTTP server\nconst server = http.createServer((req, res) => {\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('okay');\n});\nserver.on('upgrade', (req, stream, head) => {\n  stream.write('HTTP/1.1 101 Web Socket Protocol Handshake\\r\\n' +\n               'Upgrade: WebSocket\\r\\n' +\n               'Connection: Upgrade\\r\\n' +\n               '\\r\\n');\n\n  stream.pipe(stream); // echo back\n});\n\n// Now that server is running\nserver.listen(1337, '127.0.0.1', () => {\n\n  // make a request\n  const options = {\n    port: 1337,\n    host: '127.0.0.1',\n    headers: {\n      'Connection': 'Upgrade',\n      'Upgrade': 'websocket',\n    },\n  };\n\n  const req = http.request(options);\n  req.end();\n\n  req.on('upgrade', (res, stream, upgradeHead) => {\n    console.log('got upgraded!');\n    stream.end();\n    process.exit(0);\n  });\n});\n```\n\n```cjs\nconst http = require('node:http');\n\n// Create an HTTP server\nconst server = http.createServer((req, res) => {\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('okay');\n});\nserver.on('upgrade', (req, stream, head) => {\n  stream.write('HTTP/1.1 101 Web Socket Protocol Handshake\\r\\n' +\n               'Upgrade: WebSocket\\r\\n' +\n               'Connection: Upgrade\\r\\n' +\n               '\\r\\n');\n\n  stream.pipe(stream); // echo back\n});\n\n// Now that server is running\nserver.listen(1337, '127.0.0.1', () => {\n\n  // make a request\n  const options = {\n    port: 1337,\n    host: '127.0.0.1',\n    headers: {\n      'Connection': 'Upgrade',\n      'Upgrade': 'websocket',\n    },\n  };\n\n  const req = http.request(options);\n  req.end();\n\n  req.on('upgrade', (res, stream, upgradeHead) => {\n    console.log('got upgraded!');\n    stream.end();\n    process.exit(0);\n  });\n});\n```","summary":"Emitted each time a server responds to a request with an upgrade. If this event is not being listened for and the response status code is 101 Switching Protocols, clients receiving an upgrade header will have their connections closed.","examples":[{"language":"mjs","displayName":null,"code":"import http from 'node:http';\nimport process from 'node:process';\n\n// Create an HTTP server\nconst server = http.createServer((req, res) => {\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('okay');\n});\nserver.on('upgrade', (req, stream, head) => {\n  stream.write('HTTP/1.1 101 Web Socket Protocol Handshake\\r\\n' +\n               'Upgrade: WebSocket\\r\\n' +\n               'Connection: Upgrade\\r\\n' +\n               '\\r\\n');\n\n  stream.pipe(stream); // echo back\n});\n\n// Now that server is running\nserver.listen(1337, '127.0.0.1', () => {\n\n  // make a request\n  const options = {\n    port: 1337,\n    host: '127.0.0.1',\n    headers: {\n      'Connection': 'Upgrade',\n      'Upgrade': 'websocket',\n    },\n  };\n\n  const req = http.request(options);\n  req.end();\n\n  req.on('upgrade', (res, stream, upgradeHead) => {\n    console.log('got upgraded!');\n    stream.end();\n    process.exit(0);\n  });\n});"},{"language":"cjs","displayName":null,"code":"const http = require('node:http');\n\n// Create an HTTP server\nconst server = http.createServer((req, res) => {\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('okay');\n});\nserver.on('upgrade', (req, stream, head) => {\n  stream.write('HTTP/1.1 101 Web Socket Protocol Handshake\\r\\n' +\n               'Upgrade: WebSocket\\r\\n' +\n               'Connection: Upgrade\\r\\n' +\n               '\\r\\n');\n\n  stream.pipe(stream); // echo back\n});\n\n// Now that server is running\nserver.listen(1337, '127.0.0.1', () => {\n\n  // make a request\n  const options = {\n    port: 1337,\n    host: '127.0.0.1',\n    headers: {\n      'Connection': 'Upgrade',\n      'Upgrade': 'websocket',\n    },\n  };\n\n  const req = http.request(options);\n  req.end();\n\n  req.on('upgrade', (res, stream, upgradeHead) => {\n    console.log('got upgraded!');\n    stream.end();\n    process.exit(0);\n  });\n});"}],"children":[]},{"kind":"method","id":"requestabort","name":"abort","title":"`request.abort()`","scope":"module","overloadOf":null,"stability":{"index":"0","description":"Deprecated: Use [`request.destroy()`](#requestdestroyerror) instead."},"added":["v0.3.8"],"deprecated":["v14.1.0","v13.14.0"],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Marks the request as aborting. Calling this will cause remaining data\nin the response to be dropped and the socket to be destroyed.","summary":"Marks the request as aborting. Calling this will cause remaining data in the response to be dropped and the socket to be destroyed.","examples":[],"children":[]},{"kind":"property","id":"requestaborted","name":"aborted","title":"`request.aborted`","scope":"module","overloadOf":null,"stability":{"index":"0","description":"Deprecated. Check [`request.destroyed`](#requestdestroyed) instead."},"added":["v0.11.14"],"deprecated":["v17.0.0","v16.12.0"],"removed":[],"napiVersion":[],"changes":[{"versions":["v11.0.0"],"prUrl":"https://github.com/nodejs/node/pull/20230","commit":null,"description":"The `aborted` property is no longer a timestamp number."}],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"The `request.aborted` property will be `true` if the request has\nbeen aborted.","summary":"The `request.aborted` property will be `true` if the request has been aborted.","examples":[],"children":[]},{"kind":"property","id":"requestconnection","name":"connection","title":"`request.connection`","scope":"module","overloadOf":null,"stability":{"index":"0","description":"Deprecated. Use [`request.socket`](#requestsocket)."},"added":["v0.3.0"],"deprecated":["v13.0.0"],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"default":null,"description":"See [`request.socket`](#requestsocket).","summary":"See `request.socket`.","examples":[],"children":[]},{"kind":"method","id":"requestcork","name":"cork","title":"`request.cork()`","scope":"module","overloadOf":null,"stability":null,"added":["v13.2.0","v12.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"See [`writable.cork()`](stream.html#writablecork).","summary":"See `writable.cork()`.","examples":[],"children":[]},{"kind":"method","id":"requestenddata-encoding-callback","name":"end","title":"`request.end([data[, encoding]][, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.0.0"],"prUrl":"https://github.com/nodejs/node/pull/33155","commit":null,"description":"The `data` parameter can now be a `Uint8Array`."},{"versions":["v10.0.0"],"prUrl":"https://github.com/nodejs/node/pull/18780","commit":null,"description":"This method now returns a reference to `ClientRequest`."}],"signature":{"parameters":[{"name":"data","type":{"text":"string | Buffer | Uint8Array","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"Buffer","href":"buffer.html#class-buffer","start":9,"end":15},{"name":"Uint8Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array","start":18,"end":28}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]},{"name":"encoding","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"this","links":[{"name":"this","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/this","start":0,"end":4}]},"description":""}},"description":"Finishes sending the request. If any parts of the body are\nunsent, it will flush them to the stream. If the request is\nchunked, this will send the terminating `'0\\r\\n\\r\\n'`.\n\nIf `data` is specified, it is equivalent to calling\n[`request.write(data, encoding)`](#requestwritechunk-encoding-callback) followed by `request.end(callback)`.\n\nIf `callback` is specified, it will be called when the request stream\nis finished.","summary":"Finishes sending the request. If any parts of the body are unsent, it will flush them to the stream. If the request is chunked, this will send the terminating `'0\\r\\n\\r\\n'`.","examples":[],"children":[]},{"kind":"method","id":"requestdestroyerror","name":"destroy","title":"`request.destroy([error])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v14.5.0"],"prUrl":"https://github.com/nodejs/node/pull/32789","commit":null,"description":"The function returns `this` for consistency with other Readable streams."}],"signature":{"parameters":[{"name":"error","type":{"text":"Error","links":[{"name":"Error","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error","start":0,"end":5}]},"description":"Optional, an error to emit with `'error'` event.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"this","links":[{"name":"this","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/this","start":0,"end":4}]},"description":""}},"description":"Destroy the request. Optionally emit an `'error'` event,\nand emit a `'close'` event. Calling this will cause remaining data\nin the response to be dropped, and the socket to be destroyed if used,\nor returned to the corresponding Agent pool otherwise if possible.\n\nSee [`writable.destroy()`](stream.html#writabledestroyerror) for further details.","summary":"Destroy the request. Optionally emit an `'error'` event, and emit a `'close'` event. Calling this will cause remaining data in the response to be dropped, and the socket to be destroyed if used, or returned to the corresponding Agent pool otherwise if possible.","examples":[],"children":[{"kind":"property","id":"requestdestroyed","name":"destroyed","title":"`request.destroyed`","scope":"module","overloadOf":null,"stability":null,"added":["v14.1.0","v13.14.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Is `true` after [`request.destroy()`](#requestdestroyerror) has been called.\n\nSee [`writable.destroyed`](stream.html#writabledestroyed) for further details.","summary":"Is `true` after `request.destroy()` has been called.","examples":[],"children":[]}]},{"kind":"property","id":"requestfinished","name":"finished","title":"`request.finished`","scope":"module","overloadOf":null,"stability":{"index":"0","description":"Deprecated. Use [`request.writableEnded`](#requestwritableended)."},"added":["v0.0.1"],"deprecated":["v13.4.0","v12.16.0"],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"The `request.finished` property will be `true` if [`request.end()`](#requestenddata-encoding-callback)\nhas been called. `request.end()` will automatically be called if the\nrequest was initiated via [`http.get()`](#httpgetoptions-callback).","summary":"The `request.finished` property will be `true` if `request.end()` has been called. `request.end()` will automatically be called if the request was initiated via `http.get()`.","examples":[],"children":[]},{"kind":"method","id":"requestflushheaders","name":"flushHeaders","title":"`request.flushHeaders()`","scope":"module","overloadOf":null,"stability":null,"added":["v1.6.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Flushes the request headers.\n\nFor efficiency reasons, Node.js normally buffers the request headers until\n`request.end()` is called or the first chunk of request data is written. It\nthen tries to pack the request headers and data into a single TCP packet.\n\nThat's usually desired (it saves a TCP round-trip), but not when the first\ndata is not sent until possibly much later. `request.flushHeaders()` bypasses\nthe optimization and kickstarts the request.","summary":"Flushes the request headers.","examples":[],"children":[]},{"kind":"method","id":"requestgetheadername","name":"getHeader","title":"`request.getHeader(name)`","scope":"module","overloadOf":null,"stability":null,"added":["v1.6.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"any","links":[{"name":"any","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types","start":0,"end":3}]},"description":""}},"description":"Reads out a header on the request. The name is case-insensitive.\nThe type of the return value depends on the arguments provided to\n[`request.setHeader()`](#requestsetheadername-value).\n\n```js\nrequest.setHeader('content-type', 'text/html');\nrequest.setHeader('Content-Length', Buffer.byteLength(body));\nrequest.setHeader('Cookie', ['type=ninja', 'language=javascript']);\nconst contentType = request.getHeader('Content-Type');\n// 'contentType' is 'text/html'\nconst contentLength = request.getHeader('Content-Length');\n// 'contentLength' is of type number\nconst cookie = request.getHeader('Cookie');\n// 'cookie' is of type string[]\n```","summary":"Reads out a header on the request. The name is case-insensitive. The type of the return value depends on the arguments provided to `request.setHeader()`.","examples":[{"language":"js","displayName":null,"code":"request.setHeader('content-type', 'text/html');\nrequest.setHeader('Content-Length', Buffer.byteLength(body));\nrequest.setHeader('Cookie', ['type=ninja', 'language=javascript']);\nconst contentType = request.getHeader('Content-Type');\n// 'contentType' is 'text/html'\nconst contentLength = request.getHeader('Content-Length');\n// 'contentLength' is of type number\nconst cookie = request.getHeader('Cookie');\n// 'cookie' is of type string[]"}],"children":[]},{"kind":"method","id":"requestgetheadernames","name":"getHeaderNames","title":"`request.getHeaderNames()`","scope":"module","overloadOf":null,"stability":null,"added":["v7.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"Returns an array containing the unique names of the current outgoing headers.\nAll header names are lowercase.\n\n```js\nrequest.setHeader('Foo', 'bar');\nrequest.setHeader('Cookie', ['foo=bar', 'bar=baz']);\n\nconst headerNames = request.getHeaderNames();\n// headerNames === ['foo', 'cookie']\n```","summary":"Returns an array containing the unique names of the current outgoing headers. All header names are lowercase.","examples":[{"language":"js","displayName":null,"code":"request.setHeader('Foo', 'bar');\nrequest.setHeader('Cookie', ['foo=bar', 'bar=baz']);\n\nconst headerNames = request.getHeaderNames();\n// headerNames === ['foo', 'cookie']"}],"children":[]},{"kind":"method","id":"requestgetheaders","name":"getHeaders","title":"`request.getHeaders()`","scope":"module","overloadOf":null,"stability":null,"added":["v7.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":""}},"description":"Returns a shallow copy of the current outgoing headers. Since a shallow copy\nis used, array values may be mutated without additional calls to various\nheader-related http module methods. The keys of the returned object are the\nheader names and the values are the respective header values. All header names\nare lowercase.\n\nThe object returned by the `request.getHeaders()` method *does not*\nprototypically inherit from the JavaScript `Object`. This means that typical\n`Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`, and others\nare not defined and *will not work*.\n\n```js\nrequest.setHeader('Foo', 'bar');\nrequest.setHeader('Cookie', ['foo=bar', 'bar=baz']);\n\nconst headers = request.getHeaders();\n// headers === { foo: 'bar', 'cookie': ['foo=bar', 'bar=baz'] }\n```","summary":"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.","examples":[{"language":"js","displayName":null,"code":"request.setHeader('Foo', 'bar');\nrequest.setHeader('Cookie', ['foo=bar', 'bar=baz']);\n\nconst headers = request.getHeaders();\n// headers === { foo: 'bar', 'cookie': ['foo=bar', 'bar=baz'] }"}],"children":[]},{"kind":"method","id":"requestgetrawheadernames","name":"getRawHeaderNames","title":"`request.getRawHeaderNames()`","scope":"module","overloadOf":null,"stability":null,"added":["v15.13.0","v14.17.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"Returns an array containing the unique names of the current outgoing raw\nheaders. Header names are returned with their exact casing being set.\n\n```js\nrequest.setHeader('Foo', 'bar');\nrequest.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);\n\nconst headerNames = request.getRawHeaderNames();\n// headerNames === ['Foo', 'Set-Cookie']\n```","summary":"Returns an array containing the unique names of the current outgoing raw headers. Header names are returned with their exact casing being set.","examples":[{"language":"js","displayName":null,"code":"request.setHeader('Foo', 'bar');\nrequest.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);\n\nconst headerNames = request.getRawHeaderNames();\n// headerNames === ['Foo', 'Set-Cookie']"}],"children":[]},{"kind":"method","id":"requesthasheadername","name":"hasHeader","title":"`request.hasHeader(name)`","scope":"module","overloadOf":null,"stability":null,"added":["v7.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":""}},"description":"Returns `true` if the header identified by `name` is currently set in the\noutgoing headers. The header name matching is case-insensitive.\n\n```js\nconst hasContentType = request.hasHeader('content-type');\n```","summary":"Returns `true` if the header identified by `name` is currently set in the outgoing headers. The header name matching is case-insensitive.","examples":[{"language":"js","displayName":null,"code":"const hasContentType = request.hasHeader('content-type');"}],"children":[]},{"kind":"property","id":"requestmaxheaderscount","name":"maxHeadersCount","title":"`request.maxHeadersCount`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":"2000","description":"Limits maximum response headers count. If set to 0, no limit will be applied.","summary":"Limits maximum response headers count. If set to 0, no limit will be applied.","examples":[],"children":[]},{"kind":"property","id":"requestpath","name":"path","title":"`request.path`","scope":"module","overloadOf":null,"stability":null,"added":["v0.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"The request path.","summary":"","examples":[],"children":[]},{"kind":"property","id":"requestmethod","name":"method","title":"`request.method`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.97"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"The request method.","summary":"","examples":[],"children":[]},{"kind":"property","id":"requesthost","name":"host","title":"`request.host`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0","v12.19.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"The request host.","summary":"","examples":[],"children":[]},{"kind":"property","id":"requestprotocol","name":"protocol","title":"`request.protocol`","scope":"module","overloadOf":null,"stability":null,"added":["v14.5.0","v12.19.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"The request protocol.","summary":"","examples":[],"children":[]},{"kind":"method","id":"requestremoveheadername","name":"removeHeader","title":"`request.removeHeader(name)`","scope":"module","overloadOf":null,"stability":null,"added":["v1.6.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Removes a header that's already defined into headers object.\n\n```js\nrequest.removeHeader('Content-Type');\n```","summary":"Removes a header that's already defined into headers object.","examples":[{"language":"js","displayName":null,"code":"request.removeHeader('Content-Type');"}],"children":[]},{"kind":"property","id":"requestreusedsocket","name":"reusedSocket","title":"`request.reusedSocket`","scope":"module","overloadOf":null,"stability":null,"added":["v13.0.0","v12.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Whether the request is sent through a reused socket.\n\nWhen sending request through a keep-alive enabled agent, the underlying socket\nmight be reused. But if server closes connection at unfortunate time, client\nmay run into a 'ECONNRESET' error.\n\n```mjs\nimport http from 'node:http';\nconst agent = new http.Agent({ keepAlive: true });\n\n// Server has a 5 seconds keep-alive timeout by default\nhttp\n  .createServer((req, res) => {\n    res.write('hello\\n');\n    res.end();\n  })\n  .listen(3000);\n\nsetInterval(() => {\n  // Adapting a keep-alive agent\n  http.get('http://localhost:3000', { agent }, (res) => {\n    res.on('data', (data) => {\n      // Do nothing\n    });\n  });\n}, 5000); // Sending request on 5s interval so it's easy to hit idle timeout\n```\n\n```cjs\nconst http = require('node:http');\nconst agent = new http.Agent({ keepAlive: true });\n\n// Server has a 5 seconds keep-alive timeout by default\nhttp\n  .createServer((req, res) => {\n    res.write('hello\\n');\n    res.end();\n  })\n  .listen(3000);\n\nsetInterval(() => {\n  // Adapting a keep-alive agent\n  http.get('http://localhost:3000', { agent }, (res) => {\n    res.on('data', (data) => {\n      // Do nothing\n    });\n  });\n}, 5000); // Sending request on 5s interval so it's easy to hit idle timeout\n```\n\nBy marking a request whether it reused socket or not, we can do\nautomatic error retry base on it.\n\n```mjs\nimport http from 'node:http';\nconst agent = new http.Agent({ keepAlive: true });\n\nfunction retriableRequest() {\n  const req = http\n    .get('http://localhost:3000', { agent }, (res) => {\n      // ...\n    })\n    .on('error', (err) => {\n      // Check if retry is needed\n      if (req.reusedSocket && err.code === 'ECONNRESET') {\n        retriableRequest();\n      }\n    });\n}\n\nretriableRequest();\n```\n\n```cjs\nconst http = require('node:http');\nconst agent = new http.Agent({ keepAlive: true });\n\nfunction retriableRequest() {\n  const req = http\n    .get('http://localhost:3000', { agent }, (res) => {\n      // ...\n    })\n    .on('error', (err) => {\n      // Check if retry is needed\n      if (req.reusedSocket && err.code === 'ECONNRESET') {\n        retriableRequest();\n      }\n    });\n}\n\nretriableRequest();\n```","summary":"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.","examples":[{"language":"mjs","displayName":null,"code":"import http from 'node:http';\nconst agent = new http.Agent({ keepAlive: true });\n\n// Server has a 5 seconds keep-alive timeout by default\nhttp\n  .createServer((req, res) => {\n    res.write('hello\\n');\n    res.end();\n  })\n  .listen(3000);\n\nsetInterval(() => {\n  // Adapting a keep-alive agent\n  http.get('http://localhost:3000', { agent }, (res) => {\n    res.on('data', (data) => {\n      // Do nothing\n    });\n  });\n}, 5000); // Sending request on 5s interval so it's easy to hit idle timeout"},{"language":"cjs","displayName":null,"code":"const http = require('node:http');\nconst agent = new http.Agent({ keepAlive: true });\n\n// Server has a 5 seconds keep-alive timeout by default\nhttp\n  .createServer((req, res) => {\n    res.write('hello\\n');\n    res.end();\n  })\n  .listen(3000);\n\nsetInterval(() => {\n  // Adapting a keep-alive agent\n  http.get('http://localhost:3000', { agent }, (res) => {\n    res.on('data', (data) => {\n      // Do nothing\n    });\n  });\n}, 5000); // Sending request on 5s interval so it's easy to hit idle timeout"},{"language":"mjs","displayName":null,"code":"import http from 'node:http';\nconst agent = new http.Agent({ keepAlive: true });\n\nfunction retriableRequest() {\n  const req = http\n    .get('http://localhost:3000', { agent }, (res) => {\n      // ...\n    })\n    .on('error', (err) => {\n      // Check if retry is needed\n      if (req.reusedSocket && err.code === 'ECONNRESET') {\n        retriableRequest();\n      }\n    });\n}\n\nretriableRequest();"},{"language":"cjs","displayName":null,"code":"const http = require('node:http');\nconst agent = new http.Agent({ keepAlive: true });\n\nfunction retriableRequest() {\n  const req = http\n    .get('http://localhost:3000', { agent }, (res) => {\n      // ...\n    })\n    .on('error', (err) => {\n      // Check if retry is needed\n      if (req.reusedSocket && err.code === 'ECONNRESET') {\n        retriableRequest();\n      }\n    });\n}\n\nretriableRequest();"}],"children":[]},{"kind":"method","id":"requestsetheadername-value","name":"setHeader","title":"`request.setHeader(name, value)`","scope":"module","overloadOf":null,"stability":null,"added":["v1.6.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"value","type":{"text":"any","links":[{"name":"any","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types","start":0,"end":3}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Sets a single header value for headers object. If this header already exists in\nthe to-be-sent headers, its value will be replaced. Use an array of strings\nhere to send multiple headers with the same name. Non-string values will be\nstored without modification. Therefore, [`request.getHeader()`](#requestgetheadername) may return\nnon-string values. However, the non-string values will be converted to strings\nfor network transmission.\n\n```js\nrequest.setHeader('Content-Type', 'application/json');\n```\n\nor\n\n```js\nrequest.setHeader('Cookie', ['type=ninja', 'language=javascript']);\n```\n\nWhen the value is a string an exception will be thrown if it contains\ncharacters outside the `latin1` encoding.\n\nIf you need to pass UTF-8 characters in the value please encode the value\nusing the [RFC 8187](https://www.rfc-editor.org/rfc/rfc8187.txt) standard.\n\n```js\nconst filename = 'Rock 🎵.txt';\nrequest.setHeader('Content-Disposition', `attachment; filename*=utf-8''${encodeURIComponent(filename)}`);\n```","summary":"Sets a single header value for headers object. If this header already exists in the to-be-sent headers, its value will be replaced. Use an array of strings here to send multiple headers with the same name. Non-string values will be stored without modification. Therefore, `request.getHeader()` may return non-string values. However, the non-string values will be converted to strings for network transmission.","examples":[{"language":"js","displayName":null,"code":"request.setHeader('Content-Type', 'application/json');"},{"language":"js","displayName":null,"code":"request.setHeader('Cookie', ['type=ninja', 'language=javascript']);"},{"language":"js","displayName":null,"code":"const filename = 'Rock 🎵.txt';\nrequest.setHeader('Content-Disposition', `attachment; filename*=utf-8''${encodeURIComponent(filename)}`);"}],"children":[]},{"kind":"method","id":"requestsetnodelaynodelay","name":"setNoDelay","title":"`request.setNoDelay([noDelay])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.9"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"noDelay","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Once a socket is assigned to this request and is connected\n[`socket.setNoDelay()`](net.html#socketsetnodelaynodelay) will be called.","summary":"Once a socket is assigned to this request and is connected `socket.setNoDelay()` will be called.","examples":[],"children":[]},{"kind":"method","id":"requestsetsocketkeepaliveenable-initialdelay","name":"setSocketKeepAlive","title":"`request.setSocketKeepAlive([enable][, initialDelay])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.9"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"enable","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]},{"name":"initialDelay","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Once a socket is assigned to this request and is connected\n[`socket.setKeepAlive()`](net.html#socketsetkeepalive) will be called.","summary":"Once a socket is assigned to this request and is connected `socket.setKeepAlive()` will be called.","examples":[],"children":[]},{"kind":"method","id":"requestsettimeouttimeout-callback","name":"setTimeout","title":"`request.setTimeout(timeout[, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.9"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v9.0.0"],"prUrl":"https://github.com/nodejs/node/pull/8895","commit":null,"description":"Consistently set socket timeout only when the socket connects."}],"signature":{"parameters":[{"name":"timeout","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Milliseconds before a request times out.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Optional function to be called when a timeout occurs.\nSame as binding to the `'timeout'` event.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"http.ClientRequest","links":[{"name":"http.ClientRequest","href":"http.html#class-httpclientrequest","start":0,"end":18}]},"description":""}},"description":"Once a socket is assigned to this request and is connected\n[`socket.setTimeout()`](net.html#socketsettimeouttimeout-callback) will be called.","summary":"Once a socket is assigned to this request and is connected `socket.setTimeout()` will be called.","examples":[],"children":[]},{"kind":"property","id":"requestsocket","name":"socket","title":"`request.socket`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"default":null,"description":"Reference to the underlying socket. Usually users will not want to access\nthis property. In particular, the socket will not emit `'readable'` events\nbecause of how the protocol parser attaches to the socket.\n\n```mjs\nimport http from 'node:http';\nconst options = {\n  host: 'www.google.com',\n};\nconst req = http.get(options);\nreq.end();\nreq.once('response', (res) => {\n  const ip = req.socket.localAddress;\n  const port = req.socket.localPort;\n  console.log(`Your IP address is ${ip} and your source port is ${port}.`);\n  // Consume response object\n});\n```\n\n```cjs\nconst http = require('node:http');\nconst options = {\n  host: 'www.google.com',\n};\nconst req = http.get(options);\nreq.end();\nreq.once('response', (res) => {\n  const ip = req.socket.localAddress;\n  const port = req.socket.localPort;\n  console.log(`Your IP address is ${ip} and your source port is ${port}.`);\n  // Consume response object\n});\n```\n\nThis property is guaranteed to be an instance of the {net.Socket} class,\na subclass of {stream.Duplex}, unless the user specified a socket\ntype other than {net.Socket}.","summary":"Reference to the underlying socket. Usually users will not want to access this property. In particular, the socket will not emit `'readable'` events because of how the protocol parser attaches to the socket.","examples":[{"language":"mjs","displayName":null,"code":"import http from 'node:http';\nconst options = {\n  host: 'www.google.com',\n};\nconst req = http.get(options);\nreq.end();\nreq.once('response', (res) => {\n  const ip = req.socket.localAddress;\n  const port = req.socket.localPort;\n  console.log(`Your IP address is ${ip} and your source port is ${port}.`);\n  // Consume response object\n});"},{"language":"cjs","displayName":null,"code":"const http = require('node:http');\nconst options = {\n  host: 'www.google.com',\n};\nconst req = http.get(options);\nreq.end();\nreq.once('response', (res) => {\n  const ip = req.socket.localAddress;\n  const port = req.socket.localPort;\n  console.log(`Your IP address is ${ip} and your source port is ${port}.`);\n  // Consume response object\n});"}],"children":[]},{"kind":"method","id":"requestuncork","name":"uncork","title":"`request.uncork()`","scope":"module","overloadOf":null,"stability":null,"added":["v13.2.0","v12.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"See [`writable.uncork()`](stream.html#writableuncork).","summary":"See `writable.uncork()`.","examples":[],"children":[]},{"kind":"property","id":"requestwritableended","name":"writableEnded","title":"`request.writableEnded`","scope":"module","overloadOf":null,"stability":null,"added":["v12.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Is `true` after [`request.end()`](#requestenddata-encoding-callback) has been called. This property\ndoes not indicate whether the data has been flushed, for this use\n[`request.writableFinished`](#requestwritablefinished) instead.","summary":"Is `true` after `request.end()` has been called. This property does not indicate whether the data has been flushed, for this use `request.writableFinished` instead.","examples":[],"children":[]},{"kind":"property","id":"requestwritablefinished","name":"writableFinished","title":"`request.writableFinished`","scope":"module","overloadOf":null,"stability":null,"added":["v12.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Is `true` if all data has been flushed to the underlying system, immediately\nbefore the [`'finish'`](#event-finish) event is emitted.","summary":"Is `true` if all data has been flushed to the underlying system, immediately before the `'finish'` event is emitted.","examples":[],"children":[]},{"kind":"method","id":"requestwritechunk-encoding-callback","name":"write","title":"`request.write(chunk[, encoding][, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.29"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.0.0"],"prUrl":"https://github.com/nodejs/node/pull/33155","commit":null,"description":"The `chunk` parameter can now be a `Uint8Array`."}],"signature":{"parameters":[{"name":"chunk","type":{"text":"string | Buffer | Uint8Array","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"Buffer","href":"buffer.html#class-buffer","start":9,"end":15},{"name":"Uint8Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array","start":18,"end":28}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"encoding","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":""}},"description":"Sends a chunk of the body. This method can be called multiple times. If no\n`Content-Length` is set, data will automatically be encoded in HTTP Chunked\ntransfer encoding, so that server knows when the data ends. The\n`Transfer-Encoding: chunked` header is added. Calling [`request.end()`](#requestenddata-encoding-callback)\nis necessary to finish sending the request.\n\nThe `encoding` argument is optional and only applies when `chunk` is a string.\nDefaults to `'utf8'`.\n\nThe `callback` argument is optional and will be called when this chunk of data\nis flushed, but only if the chunk is non-empty.\n\nReturns `true` if the entire data was flushed successfully to the kernel\nbuffer. Returns `false` if all or part of the data was queued in user memory.\n`'drain'` will be emitted when the buffer is free again.\n\nWhen `write` function is called with empty string or buffer, it does\nnothing and waits for more input.","summary":"Sends a chunk of the body. This method can be called multiple times. If no `Content-Length` is set, data will automatically be encoded in HTTP Chunked transfer encoding, so that server knows when the data ends. The `Transfer-Encoding: chunked` header is added. Calling `request.end()` is necessary to finish sending the request.","examples":[],"children":[]}]},{"kind":"class","id":"class-httpserver","name":"Server","title":"Class: `http.Server`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.17"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":{"text":"net.Server","links":[{"name":"net.Server","href":"net.html#class-netserver","start":0,"end":10}]},"description":"","summary":"","examples":[],"children":[{"kind":"event","id":"event-checkcontinue","name":"checkContinue","title":"Event: `'checkContinue'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"request","type":{"text":"http.IncomingMessage","links":[{"name":"http.IncomingMessage","href":"http.html#class-httpincomingmessage","start":0,"end":20}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"response","type":{"text":"http.ServerResponse","links":[{"name":"http.ServerResponse","href":"http.html#class-httpserverresponse","start":0,"end":19}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"description":"Emitted each time a request with an HTTP `Expect: 100-continue` is received.\nIf this event is not listened for, the server will automatically respond\nwith a `100 Continue` as appropriate.\n\nHandling this event involves calling [`response.writeContinue()`](#responsewritecontinue) if the\nclient should continue to send the request body, or generating an appropriate\nHTTP response (e.g. 400 Bad Request) if the client should not continue to send\nthe request body.\n\nWhen this event is emitted and handled, the [`'request'`](#event-request) event will\nnot be emitted.","summary":"Emitted each time a request with an HTTP `Expect: 100-continue` is received. If this event is not listened for, the server will automatically respond with a `100 Continue` as appropriate.","examples":[],"children":[]},{"kind":"event","id":"event-checkexpectation","name":"checkExpectation","title":"Event: `'checkExpectation'`","scope":"module","overloadOf":null,"stability":null,"added":["v5.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"request","type":{"text":"http.IncomingMessage","links":[{"name":"http.IncomingMessage","href":"http.html#class-httpincomingmessage","start":0,"end":20}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"response","type":{"text":"http.ServerResponse","links":[{"name":"http.ServerResponse","href":"http.html#class-httpserverresponse","start":0,"end":19}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"description":"Emitted each time a request with an HTTP `Expect` header is received, where the\nvalue is not `100-continue`. If this event is not listened for, the server will\nautomatically respond with a `417 Expectation Failed` as appropriate.\n\nWhen this event is emitted and handled, the [`'request'`](#event-request) event will\nnot be emitted.","summary":"Emitted each time a request with an HTTP `Expect` header is received, where the value is not `100-continue`. If this event is not listened for, the server will automatically respond with a `417 Expectation Failed` as appropriate.","examples":[],"children":[]},{"kind":"event","id":"event-clienterror","name":"clientError","title":"Event: `'clientError'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.94"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v12.0.0"],"prUrl":"https://github.com/nodejs/node/pull/25605","commit":null,"description":"The default behavior will return a 431 Request Header Fields Too Large if an HPE_HEADER_OVERFLOW error occurs."},{"versions":["v9.4.0"],"prUrl":"https://github.com/nodejs/node/pull/17672","commit":null,"description":"The `rawPacket` is the current buffer that just parsed. Adding this buffer to the error object of `'clientError'` event is to make it possible that developers can log the broken packet."},{"versions":["v6.0.0"],"prUrl":"https://github.com/nodejs/node/pull/4557","commit":null,"description":"The default action of calling `.destroy()` on the `socket` will no longer take place if there are listeners attached for `'clientError'`."}],"parameters":[{"name":"exception","type":{"text":"Error","links":[{"name":"Error","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error","start":0,"end":5}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"socket","type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"description":"If a client connection emits an `'error'` event, it will be forwarded here.\nListener of this event is responsible for closing/destroying the underlying\nsocket. For example, one may wish to more gracefully close the socket with a\ncustom HTTP response instead of abruptly severing the connection. The socket\n**must be closed or destroyed** before the listener ends.\n\nThis event is guaranteed to be passed an instance of the {net.Socket} class,\na subclass of {stream.Duplex}, unless the user specifies a socket\ntype other than {net.Socket}.\n\nDefault behavior is to try close the socket with an HTTP '400 Bad Request',\nor an HTTP '431 Request Header Fields Too Large' in the case of an\n[`HPE_HEADER_OVERFLOW`](errors.html#hpe_header_overflow) error. If the socket is not writable or headers\nof the current attached [`http.ServerResponse`](#class-httpserverresponse) has been sent, it is\nimmediately destroyed.\n\n`socket` is the [`net.Socket`](net.html#class-netsocket) object that the error originated from.\n\n```mjs\nimport http from 'node:http';\n\nconst server = http.createServer((req, res) => {\n  res.end();\n});\nserver.on('clientError', (err, socket) => {\n  socket.end('HTTP/1.1 400 Bad Request\\r\\n\\r\\n');\n});\nserver.listen(8000);\n```\n\n```cjs\nconst http = require('node:http');\n\nconst server = http.createServer((req, res) => {\n  res.end();\n});\nserver.on('clientError', (err, socket) => {\n  socket.end('HTTP/1.1 400 Bad Request\\r\\n\\r\\n');\n});\nserver.listen(8000);\n```\n\nWhen the `'clientError'` event occurs, there is no `request` or `response`\nobject, so any HTTP response sent, including response headers and payload,\n*must* be written directly to the `socket` object. Care must be taken to\nensure the response is a properly formatted HTTP response message.\n\n`err` is an instance of `Error` with two extra columns:\n\n* `bytesParsed`: the bytes count of request packet that Node.js may have parsed\n  correctly;\n* `rawPacket`: the raw packet of current request.\n\nIn some cases, the client has already received the response and/or the socket\nhas already been destroyed, like in case of `ECONNRESET` errors. Before\ntrying to send data to the socket, it is better to check that it is still\nwritable.\n\n```js\nserver.on('clientError', (err, socket) => {\n  if (err.code === 'ECONNRESET' || !socket.writable) {\n    return;\n  }\n\n  socket.end('HTTP/1.1 400 Bad Request\\r\\n\\r\\n');\n});\n```","summary":"If a client connection emits an `'error'` event, it will be forwarded here. Listener of this event is responsible for closing/destroying the underlying socket. For example, one may wish to more gracefully close the socket with a custom HTTP response instead of abruptly severing the connection. The socket **must be closed or destroyed** before the listener ends.","examples":[{"language":"mjs","displayName":null,"code":"import http from 'node:http';\n\nconst server = http.createServer((req, res) => {\n  res.end();\n});\nserver.on('clientError', (err, socket) => {\n  socket.end('HTTP/1.1 400 Bad Request\\r\\n\\r\\n');\n});\nserver.listen(8000);"},{"language":"cjs","displayName":null,"code":"const http = require('node:http');\n\nconst server = http.createServer((req, res) => {\n  res.end();\n});\nserver.on('clientError', (err, socket) => {\n  socket.end('HTTP/1.1 400 Bad Request\\r\\n\\r\\n');\n});\nserver.listen(8000);"},{"language":"js","displayName":null,"code":"server.on('clientError', (err, socket) => {\n  if (err.code === 'ECONNRESET' || !socket.writable) {\n    return;\n  }\n\n  socket.end('HTTP/1.1 400 Bad Request\\r\\n\\r\\n');\n});"}],"children":[]},{"kind":"event","id":"event-close-1","name":"close","title":"Event: `'close'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.4"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Emitted when the server closes.","summary":"Emitted when the server closes.","examples":[],"children":[]},{"kind":"event","id":"event-connect-1","name":"connect","title":"Event: `'connect'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"request","type":{"text":"http.IncomingMessage","links":[{"name":"http.IncomingMessage","href":"http.html#class-httpincomingmessage","start":0,"end":20}]},"description":"Arguments for the HTTP request, as it is in\nthe [`'request'`](#event-request) event","default":null,"optional":false,"rest":false,"properties":[]},{"name":"socket","type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"description":"Network socket between the server and client","default":null,"optional":false,"rest":false,"properties":[]},{"name":"head","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"The first packet of the tunneling stream (may be empty)","default":null,"optional":false,"rest":false,"properties":[]}],"description":"Emitted each time a client requests an HTTP `CONNECT` method. If this event is\nnot listened for, then clients requesting a `CONNECT` method will have their\nconnections closed.\n\nThis event is guaranteed to be passed an instance of the {net.Socket} class,\na subclass of {stream.Duplex}, unless the user specifies a socket\ntype other than {net.Socket}.\n\nAfter this event is emitted, the request's socket will not have a `'data'`\nevent listener, meaning it will need to be bound in order to handle data\nsent to the server on that socket.","summary":"Emitted each time a client requests an HTTP `CONNECT` method. If this event is not listened for, then clients requesting a `CONNECT` method will have their connections closed.","examples":[],"children":[]},{"kind":"event","id":"event-connection","name":"connection","title":"Event: `'connection'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"socket","type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"description":"This event is emitted when a new TCP stream is established. `socket` is\ntypically an object of type [`net.Socket`](net.html#class-netsocket). Usually users will not want to\naccess this event. In particular, the socket will not emit `'readable'` events\nbecause of how the protocol parser attaches to the socket. The `socket` can\nalso be accessed at `request.socket`.\n\nThis event can also be explicitly emitted by users to inject connections\ninto the HTTP server. In that case, any [`Duplex`](stream.html#class-streamduplex) stream can be passed.\n\nIf `socket.setTimeout()` is called here, the timeout will be replaced with\n`server.keepAliveTimeout` when the socket has served a request (if\n`server.keepAliveTimeout` is non-zero).\n\nThis event is guaranteed to be passed an instance of the {net.Socket} class,\na subclass of {stream.Duplex}, unless the user specifies a socket\ntype other than {net.Socket}.","summary":"This event is emitted when a new TCP stream is established. `socket` is typically an object of type `net.Socket`. Usually users will not want to access this event. In particular, the socket will not emit `'readable'` events because of how the protocol parser attaches to the socket. The `socket` can also be accessed at `request.socket`.","examples":[],"children":[]},{"kind":"event","id":"event-droprequest","name":"dropRequest","title":"Event: `'dropRequest'`","scope":"module","overloadOf":null,"stability":null,"added":["v18.7.0","v16.17.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"request","type":{"text":"http.IncomingMessage","links":[{"name":"http.IncomingMessage","href":"http.html#class-httpincomingmessage","start":0,"end":20}]},"description":"Arguments for the HTTP request, as it is in\nthe [`'request'`](#event-request) event","default":null,"optional":false,"rest":false,"properties":[]},{"name":"socket","type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"description":"Network socket between the server and client","default":null,"optional":false,"rest":false,"properties":[]}],"description":"When the number of requests on a socket reaches the threshold of\n`server.maxRequestsPerSocket`, the server will drop new requests\nand emit `'dropRequest'` event instead, then send `503` to client.","summary":"When the number of requests on a socket reaches the threshold of `server.maxRequestsPerSocket`, the server will drop new requests and emit `'dropRequest'` event instead, then send `503` to client.","examples":[],"children":[]},{"kind":"event","id":"event-request","name":"request","title":"Event: `'request'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[{"name":"request","type":{"text":"http.IncomingMessage","links":[{"name":"http.IncomingMessage","href":"http.html#class-httpincomingmessage","start":0,"end":20}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"response","type":{"text":"http.ServerResponse","links":[{"name":"http.ServerResponse","href":"http.html#class-httpserverresponse","start":0,"end":19}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"description":"Emitted each time there is a request. There may be multiple requests\nper connection (in the case of HTTP Keep-Alive connections).","summary":"Emitted each time there is a request. There may be multiple requests per connection (in the case of HTTP Keep-Alive connections).","examples":[],"children":[]},{"kind":"event","id":"event-upgrade-1","name":"upgrade","title":"Event: `'upgrade'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.94"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v26.0.0"],"prUrl":"https://github.com/nodejs/node/pull/60016","commit":null,"description":"Request bodies are no longer exposed raw (unparsed) on the socket argument. Instead, if a body is received, the stream argument will be a duplex that emits socket content only after the request body, while the parsed request body data will be emitted from the request, just as in normal server `'request'` events."},{"versions":["v24.9.0","v22.21.0"],"prUrl":"https://github.com/nodejs/node/pull/59824","commit":null,"description":"Whether this event is fired can now be controlled by the `shouldUpgradeCallback` and sockets will be destroyed if upgraded while no event handler is listening."},{"versions":["v10.0.0"],"prUrl":"https://github.com/nodejs/node/pull/19981","commit":null,"description":"Not listening to this event no longer causes the socket to be destroyed if a client sends an Upgrade header."}],"parameters":[{"name":"request","type":{"text":"http.IncomingMessage","links":[{"name":"http.IncomingMessage","href":"http.html#class-httpincomingmessage","start":0,"end":20}]},"description":"Arguments for the HTTP request, as it is in\nthe [`'request'`](#event-request) event","default":null,"optional":false,"rest":false,"properties":[]},{"name":"stream","type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"description":"The upgraded stream between the server and client","default":null,"optional":false,"rest":false,"properties":[]},{"name":"head","type":{"text":"Buffer","links":[{"name":"Buffer","href":"buffer.html#class-buffer","start":0,"end":6}]},"description":"The first packet of the upgraded stream (may be empty)","default":null,"optional":false,"rest":false,"properties":[]}],"description":"Emitted each time a client's HTTP upgrade request is accepted. By default\nall HTTP upgrade requests are ignored (i.e. only regular `'request'` events\nare emitted, sticking with the normal HTTP request/response flow) unless you\nlisten to this event, in which case they are all accepted (i.e. the `'upgrade'`\nevent is emitted instead, and future communication must handled directly\nthrough the raw stream). You can control this more precisely by using the\nserver `shouldUpgradeCallback` option.\n\nListening to this event is optional and clients cannot insist on a protocol\nchange.\n\nIf an upgrade is accepted by `shouldUpgradeCallback` but no event handler\nis registered then the socket will be destroyed, resulting in an immediate\nconnection closure for the client.\n\nIn the uncommon case that the incoming request has a body, this body will be\nparsed as normal, separate to the upgrade stream, and the raw stream data will\nonly begin after it has completed. To ensure that reading from the stream isn't\nblocked by waiting for the request body to be read, any reads on the stream\nwill start the request body flowing automatically. If you want to read the\nrequest body, ensure that you do so (i.e. you attach `'data'` listeners)\nbefore starting to read from the upgraded stream.\n\nThe stream argument will typically be the {net.Socket} instance used by the\nrequest, but in some cases (such as with a request body) it may be a duplex\nstream. If required, you can access the raw connection underlying the request\nvia [`request.socket`](#requestsocket), which is guaranteed to be an instance of {net.Socket}\nunless the user specified another socket type.","summary":"Emitted each time a client's HTTP upgrade request is accepted. By default all HTTP upgrade requests are ignored (i.e. only regular `'request'` events are emitted, sticking with the normal HTTP request/response flow) unless you listen to this event, in which case they are all accepted (i.e. the `'upgrade'` event is emitted instead, and future communication must handled directly through the raw stream). You can control this more precisely by using the server `shouldUpgradeCallback` option.","examples":[],"children":[]},{"kind":"method","id":"serverclosecallback","name":"close","title":"`server.close([callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v19.0.0"],"prUrl":"https://github.com/nodejs/node/pull/43522","commit":null,"description":"The method closes idle connections before returning."}],"signature":{"parameters":[{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Stops the server from accepting new connections and closes all connections\nconnected to this server which are not sending a request or waiting for\na response.\nSee [`net.Server.close()`](net.html#serverclosecallback).\n\n```js\nconst http = require('node:http');\n\nconst server = http.createServer({ keepAliveTimeout: 60000 }, (req, res) => {\n  res.writeHead(200, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({\n    data: 'Hello World!',\n  }));\n});\n\nserver.listen(8000);\n// Close the server after 10 seconds\nsetTimeout(() => {\n  server.close(() => {\n    console.log('server on port 8000 closed successfully');\n  });\n}, 10000);\n```","summary":"Stops the server from accepting new connections and closes all connections connected to this server which are not sending a request or waiting for a response. See `net.Server.close()`.","examples":[{"language":"js","displayName":null,"code":"const http = require('node:http');\n\nconst server = http.createServer({ keepAliveTimeout: 60000 }, (req, res) => {\n  res.writeHead(200, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({\n    data: 'Hello World!',\n  }));\n});\n\nserver.listen(8000);\n// Close the server after 10 seconds\nsetTimeout(() => {\n  server.close(() => {\n    console.log('server on port 8000 closed successfully');\n  });\n}, 10000);"}],"children":[]},{"kind":"method","id":"servercloseallconnections","name":"closeAllConnections","title":"`server.closeAllConnections()`","scope":"module","overloadOf":null,"stability":null,"added":["v18.2.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Closes all established HTTP(S) connections connected to this server, including\nactive connections connected to this server which are sending a request or\nwaiting for a response. This does *not* destroy sockets upgraded to a different\nprotocol, such as WebSocket or HTTP/2.\n\n> This is a forceful way of closing all connections and should be used with\n> caution. Whenever using this in conjunction with `server.close`, calling this\n> *after* `server.close` is recommended as to avoid race conditions where new\n> connections are created between a call to this and a call to `server.close`.\n\n```js\nconst http = require('node:http');\n\nconst server = http.createServer({ keepAliveTimeout: 60000 }, (req, res) => {\n  res.writeHead(200, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({\n    data: 'Hello World!',\n  }));\n});\n\nserver.listen(8000);\n// Close the server after 10 seconds\nsetTimeout(() => {\n  server.close(() => {\n    console.log('server on port 8000 closed successfully');\n  });\n  // Closes all connections, ensuring the server closes successfully\n  server.closeAllConnections();\n}, 10000);\n```","summary":"Closes all established HTTP(S) connections connected to this server, including active connections connected to this server which are sending a request or waiting for a response. This does _not_ destroy sockets upgraded to a different protocol, such as WebSocket or HTTP/2.","examples":[{"language":"js","displayName":null,"code":"const http = require('node:http');\n\nconst server = http.createServer({ keepAliveTimeout: 60000 }, (req, res) => {\n  res.writeHead(200, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({\n    data: 'Hello World!',\n  }));\n});\n\nserver.listen(8000);\n// Close the server after 10 seconds\nsetTimeout(() => {\n  server.close(() => {\n    console.log('server on port 8000 closed successfully');\n  });\n  // Closes all connections, ensuring the server closes successfully\n  server.closeAllConnections();\n}, 10000);"}],"children":[]},{"kind":"method","id":"servercloseidleconnections","name":"closeIdleConnections","title":"`server.closeIdleConnections()`","scope":"module","overloadOf":null,"stability":null,"added":["v18.2.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Closes all connections connected to this server which are not sending a request\nor waiting for a response.\n\n> Starting with Node.js 19.0.0, there's no need for calling this method in\n> conjunction with `server.close` to reap `keep-alive` connections. Using it\n> won't cause any harm though, and it can be useful to ensure backwards\n> compatibility for libraries and applications that need to support versions\n> older than 19.0.0. Whenever using this in conjunction with `server.close`,\n> calling this *after* `server.close` is recommended as to avoid race\n> conditions where new connections are created between a call to this and a\n> call to `server.close`.\n\n```js\nconst http = require('node:http');\n\nconst server = http.createServer({ keepAliveTimeout: 60000 }, (req, res) => {\n  res.writeHead(200, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({\n    data: 'Hello World!',\n  }));\n});\n\nserver.listen(8000);\n// Close the server after 10 seconds\nsetTimeout(() => {\n  server.close(() => {\n    console.log('server on port 8000 closed successfully');\n  });\n  // Closes idle connections, such as keep-alive connections. Server will close\n  // once remaining active connections are terminated\n  server.closeIdleConnections();\n}, 10000);\n```","summary":"Closes all connections connected to this server which are not sending a request or waiting for a response.","examples":[{"language":"js","displayName":null,"code":"const http = require('node:http');\n\nconst server = http.createServer({ keepAliveTimeout: 60000 }, (req, res) => {\n  res.writeHead(200, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({\n    data: 'Hello World!',\n  }));\n});\n\nserver.listen(8000);\n// Close the server after 10 seconds\nsetTimeout(() => {\n  server.close(() => {\n    console.log('server on port 8000 closed successfully');\n  });\n  // Closes idle connections, such as keep-alive connections. Server will close\n  // once remaining active connections are terminated\n  server.closeIdleConnections();\n}, 10000);"}],"children":[]},{"kind":"property","id":"serverheaderstimeout","name":"headersTimeout","title":"`server.headersTimeout`","scope":"module","overloadOf":null,"stability":null,"added":["v11.3.0","v10.14.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v19.4.0","v18.14.0"],"prUrl":"https://github.com/nodejs/node/pull/45778","commit":null,"description":"The default is now set to the minimum between 60000 (60 seconds) or `requestTimeout`."}],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":"The minimum between `server.requestTimeout` or `60000`","description":"Limit the amount of time the parser will wait to receive the complete HTTP\nheaders.\n\nIf the timeout expires, the server responds with status 408 without\nforwarding the request to the request listener and then closes the connection.\n\nIt must be set to a non-zero value (e.g. 120 seconds) to protect against\npotential Denial-of-Service attacks in case the server is deployed without a\nreverse proxy in front.","summary":"Limit the amount of time the parser will wait to receive the complete HTTP headers.","examples":[],"children":[]},{"kind":"method","id":"serverlisten","name":"listen","title":"`server.listen()`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Starts the HTTP server listening for connections.\nThis method is identical to [`server.listen()`](net.html#serverlisten) from [`net.Server`](net.html#class-netserver).","summary":"Starts the HTTP server listening for connections. This method is identical to `server.listen()` from `net.Server`.","examples":[],"children":[]},{"kind":"property","id":"serverlistening","name":"listening","title":"`server.listening`","scope":"module","overloadOf":null,"stability":null,"added":["v5.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Indicates whether or not the server is listening for connections.","summary":"","examples":[],"children":[]},{"kind":"property","id":"servermaxheaderscount","name":"maxHeadersCount","title":"`server.maxHeadersCount`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":"2000","description":"Limits maximum incoming headers count. If set to 0, no limit will be applied.","summary":"Limits maximum incoming headers count. If set to 0, no limit will be applied.","examples":[],"children":[]},{"kind":"property","id":"serverrequesttimeout","name":"requestTimeout","title":"`server.requestTimeout`","scope":"module","overloadOf":null,"stability":null,"added":["v14.11.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v18.0.0"],"prUrl":"https://github.com/nodejs/node/pull/41263","commit":null,"description":"The default request timeout changed from no timeout to 300s (5 minutes)."}],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":"300000","description":"Sets the timeout value in milliseconds for receiving the entire request from\nthe client.\n\nIf the timeout expires, the server responds with status 408 without\nforwarding the request to the request listener and then closes the connection.\n\nIt must be set to a non-zero value (e.g. 120 seconds) to protect against\npotential Denial-of-Service attacks in case the server is deployed without a\nreverse proxy in front.","summary":"Sets the timeout value in milliseconds for receiving the entire request from the client.","examples":[],"children":[]},{"kind":"method","id":"serversettimeoutmsecs-callback","name":"setTimeout","title":"`server.setTimeout([msecs][, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.12"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v13.0.0"],"prUrl":"https://github.com/nodejs/node/pull/27558","commit":null,"description":"The default timeout changed from 120s to 0 (no timeout)."}],"signature":{"parameters":[{"name":"msecs","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":"0 (no timeout)","optional":true,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"http.Server","links":[{"name":"http.Server","href":"http.html#class-httpserver","start":0,"end":11}]},"description":""}},"description":"Sets the timeout value for sockets, and emits a `'timeout'` event on\nthe Server object, passing the socket as an argument, if a timeout\noccurs.\n\nIf there is a `'timeout'` event listener on the Server object, then it\nwill be called with the timed-out socket as an argument.\n\nBy default, the Server does not timeout sockets. However, if a callback\nis assigned to the Server's `'timeout'` event, timeouts must be handled\nexplicitly.","summary":"Sets the timeout value for sockets, and emits a `'timeout'` event on the Server object, passing the socket as an argument, if a timeout occurs.","examples":[],"children":[]},{"kind":"property","id":"servermaxrequestspersocket","name":"maxRequestsPerSocket","title":"`server.maxRequestsPerSocket`","scope":"module","overloadOf":null,"stability":null,"added":["v16.10.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":"0 (no limit)","description":"Requests per socket.\n\nThe maximum number of requests socket can handle\nbefore closing keep alive connection.\n\nA value of `0` will disable the limit.\n\nWhen the limit is reached it will set the `Connection` header value to `close`,\nbut will not actually close the connection, subsequent requests sent\nafter the limit is reached will get `503 Service Unavailable` as a response.","summary":"The maximum number of requests socket can handle before closing keep alive connection.","examples":[],"children":[]},{"kind":"property","id":"servertimeout","name":"timeout","title":"`server.timeout`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.12"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v13.0.0"],"prUrl":"https://github.com/nodejs/node/pull/27558","commit":null,"description":"The default timeout changed from 120s to 0 (no timeout)."}],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":"0 (no timeout)","description":"Timeout in milliseconds.\n\nThe number of milliseconds of inactivity before a socket is presumed\nto have timed out.\n\nA value of `0` will disable the timeout behavior on incoming connections.\n\nThe socket timeout logic is set up on connection, so changing this\nvalue only affects new connections to the server, not any existing connections.","summary":"The number of milliseconds of inactivity before a socket is presumed to have timed out.","examples":[],"children":[]},{"kind":"property","id":"serverkeepalivetimeout","name":"keepAliveTimeout","title":"`server.keepAliveTimeout`","scope":"module","overloadOf":null,"stability":null,"added":["v8.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":"`5000` (5 seconds)","description":"Timeout in milliseconds.\n\nThe number of milliseconds of inactivity a server needs to wait for additional\nincoming data, after it has finished writing the last response, before a socket\nwill be destroyed.\n\nThis timeout value is combined with the\n[`server.keepAliveTimeoutBuffer`](#serverkeepalivetimeoutbuffer) option to determine the actual socket\ntimeout, calculated as:\nsocketTimeout = keepAliveTimeout + keepAliveTimeoutBuffer\nIf the server receives new data before the keep-alive timeout has fired, it\nwill reset the regular inactivity timeout, i.e., [`server.timeout`](#servertimeout).\n\nA value of `0` will disable the keep-alive timeout behavior on incoming\nconnections.\nA value of `0` makes the HTTP server behave similarly to Node.js versions prior\nto 8.0.0, which did not have a keep-alive timeout.\n\nThe socket timeout logic is set up on connection, so changing this value only\naffects new connections to the server, not any existing connections.","summary":"The number of milliseconds of inactivity a server needs to wait for additional incoming data, after it has finished writing the last response, before a socket will be destroyed.","examples":[],"children":[]},{"kind":"property","id":"serverkeepalivetimeoutbuffer","name":"keepAliveTimeoutBuffer","title":"`server.keepAliveTimeoutBuffer`","scope":"module","overloadOf":null,"stability":null,"added":["v24.6.0","v22.19.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":"`1000` (1 second)","description":"Timeout in milliseconds.\n\nAn additional buffer time added to the\n[`server.keepAliveTimeout`](#serverkeepalivetimeout) to extend the internal socket timeout.\n\nThis buffer helps reduce connection reset (`ECONNRESET`) errors by increasing\nthe socket timeout slightly beyond the advertised keep-alive timeout.\n\nThis option applies only to new incoming connections.","summary":"An additional buffer time added to the `server.keepAliveTimeout` to extend the internal socket timeout.","examples":[],"children":[]},{"kind":"method","id":"serversymbolasyncdispose","name":"[Symbol.asyncDispose]","title":"`server[Symbol.asyncDispose]()`","scope":"module","overloadOf":null,"stability":null,"added":["v20.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v24.2.0"],"prUrl":"https://github.com/nodejs/node/pull/58467","commit":null,"description":"No longer experimental."}],"signature":{"parameters":[],"returns":null},"description":"Calls [`server.close()`](#serverclosecallback) and returns a promise that fulfills when the\nserver has closed.","summary":"Calls `server.close()` and returns a promise that fulfills when the server has closed.","examples":[],"children":[]}]},{"kind":"class","id":"class-httpserverresponse","name":"ServerResponse","title":"Class: `http.ServerResponse`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.17"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":{"text":"http.OutgoingMessage","links":[{"name":"http.OutgoingMessage","href":"http.html#class-httpoutgoingmessage","start":0,"end":20}]},"description":"This object is created internally by an HTTP server, not by the user. It is\npassed as the second parameter to the [`'request'`](#event-request) event.","summary":"This object is created internally by an HTTP server, not by the user. It is passed as the second parameter to the `'request'` event.","examples":[],"children":[{"kind":"event","id":"event-close-2","name":"close","title":"Event: `'close'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.6.7"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Indicates that the response is completed, or its underlying connection was\nterminated prematurely (before the response completion).","summary":"Indicates that the response is completed, or its underlying connection was terminated prematurely (before the response completion).","examples":[],"children":[]},{"kind":"event","id":"event-finish-1","name":"finish","title":"Event: `'finish'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.6"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Emitted when the response has been sent. More specifically, this event is\nemitted when the last segment of the response headers and body have been\nhanded off to the operating system for transmission over the network. It\ndoes not imply that the client has received anything yet.","summary":"Emitted when the response has been sent. More specifically, this event is emitted when the last segment of the response headers and body have been handed off to the operating system for transmission over the network. It does not imply that the client has received anything yet.","examples":[],"children":[]},{"kind":"method","id":"responseaddtrailersheaders","name":"addTrailers","title":"`response.addTrailers(headers)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"headers","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"This method adds HTTP trailing headers (a header but at the end of the\nmessage) to the response.\n\nTrailers will **only** be emitted if chunked encoding is used for the\nresponse; if it is not (e.g. if the request was HTTP/1.0), they will\nbe silently discarded.\n\nHTTP requires the `Trailer` header to be sent in order to\nemit trailers, with a list of the header fields in its value. E.g.,\n\n```js\nresponse.writeHead(200, { 'Content-Type': 'text/plain',\n                          'Trailer': 'Content-MD5' });\nresponse.write(fileData);\nresponse.addTrailers({ 'Content-MD5': '7895bf4b8828b55ceaf47747b4bca667' });\nresponse.end();\n```\n\nAttempting to set a header field name or value that contains invalid characters\nwill result in a [`TypeError`](errors.html#class-typeerror) being thrown.","summary":"This method adds HTTP trailing headers (a header but at the end of the message) to the response.","examples":[{"language":"js","displayName":null,"code":"response.writeHead(200, { 'Content-Type': 'text/plain',\n                          'Trailer': 'Content-MD5' });\nresponse.write(fileData);\nresponse.addTrailers({ 'Content-MD5': '7895bf4b8828b55ceaf47747b4bca667' });\nresponse.end();"}],"children":[]},{"kind":"property","id":"responseconnection","name":"connection","title":"`response.connection`","scope":"module","overloadOf":null,"stability":{"index":"0","description":"Deprecated. Use [`response.socket`](#responsesocket)."},"added":["v0.3.0"],"deprecated":["v13.0.0"],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"default":null,"description":"See [`response.socket`](#responsesocket).","summary":"See `response.socket`.","examples":[],"children":[]},{"kind":"method","id":"responsecork","name":"cork","title":"`response.cork()`","scope":"module","overloadOf":null,"stability":null,"added":["v13.2.0","v12.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"See [`writable.cork()`](stream.html#writablecork).","summary":"See `writable.cork()`.","examples":[],"children":[]},{"kind":"method","id":"responseenddata-encoding-callback","name":"end","title":"`response.end([data[, encoding]][, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.0.0"],"prUrl":"https://github.com/nodejs/node/pull/33155","commit":null,"description":"The `data` parameter can now be a `Uint8Array`."},{"versions":["v10.0.0"],"prUrl":"https://github.com/nodejs/node/pull/18780","commit":null,"description":"This method now returns a reference to `ServerResponse`."}],"signature":{"parameters":[{"name":"data","type":{"text":"string | Buffer | Uint8Array","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"Buffer","href":"buffer.html#class-buffer","start":9,"end":15},{"name":"Uint8Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array","start":18,"end":28}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]},{"name":"encoding","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"this","links":[{"name":"this","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/this","start":0,"end":4}]},"description":""}},"description":"This method signals to the server that all of the response headers and body\nhave been sent; that server should consider this message complete.\nThe method, `response.end()`, MUST be called on each response.\n\nIf `data` is specified, it is similar in effect to calling\n[`response.write(data, encoding)`](#responsewritechunk-encoding-callback) followed by `response.end(callback)`.\n\nIf `callback` is specified, it will be called when the response stream\nis finished.","summary":"This method signals to the server that all of the response headers and body have been sent; that server should consider this message complete. The method, `response.end()`, MUST be called on each response.","examples":[],"children":[]},{"kind":"property","id":"responsefinished","name":"finished","title":"`response.finished`","scope":"module","overloadOf":null,"stability":{"index":"0","description":"Deprecated. Use [`response.writableEnded`](#responsewritableended)."},"added":["v0.0.2"],"deprecated":["v13.4.0","v12.16.0"],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"The `response.finished` property will be `true` if [`response.end()`](#responseenddata-encoding-callback)\nhas been called.","summary":"The `response.finished` property will be `true` if `response.end()` has been called.","examples":[],"children":[]},{"kind":"method","id":"responseflushheaders","name":"flushHeaders","title":"`response.flushHeaders()`","scope":"module","overloadOf":null,"stability":null,"added":["v1.6.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Flushes the response headers. See also: [`request.flushHeaders()`](#requestflushheaders).","summary":"Flushes the response headers. See also: `request.flushHeaders()`.","examples":[],"children":[]},{"kind":"method","id":"responsegetheadername","name":"getHeader","title":"`response.getHeader(name)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"number | string | string[] | undefined","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":9,"end":15},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":18,"end":24},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":29,"end":38}]},"description":""}},"description":"Reads out a header that's already been queued but not sent to the client.\nThe name is case-insensitive. The type of the return value depends\non the arguments provided to [`response.setHeader()`](#responsesetheadername-value).\n\n```js\nresponse.setHeader('Content-Type', 'text/html');\nresponse.setHeader('Content-Length', Buffer.byteLength(body));\nresponse.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']);\nconst contentType = response.getHeader('content-type');\n// contentType is 'text/html'\nconst contentLength = response.getHeader('Content-Length');\n// contentLength is of type number\nconst setCookie = response.getHeader('set-cookie');\n// setCookie is of type string[]\n```","summary":"Reads out a header that's already been queued but not sent to the client. The name is case-insensitive. The type of the return value depends on the arguments provided to `response.setHeader()`.","examples":[{"language":"js","displayName":null,"code":"response.setHeader('Content-Type', 'text/html');\nresponse.setHeader('Content-Length', Buffer.byteLength(body));\nresponse.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']);\nconst contentType = response.getHeader('content-type');\n// contentType is 'text/html'\nconst contentLength = response.getHeader('Content-Length');\n// contentLength is of type number\nconst setCookie = response.getHeader('set-cookie');\n// setCookie is of type string[]"}],"children":[]},{"kind":"method","id":"responsegetheadernames","name":"getHeaderNames","title":"`response.getHeaderNames()`","scope":"module","overloadOf":null,"stability":null,"added":["v7.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"Returns an array containing the unique names of the current outgoing headers.\nAll header names are lowercase.\n\n```js\nresponse.setHeader('Foo', 'bar');\nresponse.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);\n\nconst headerNames = response.getHeaderNames();\n// headerNames === ['foo', 'set-cookie']\n```","summary":"Returns an array containing the unique names of the current outgoing headers. All header names are lowercase.","examples":[{"language":"js","displayName":null,"code":"response.setHeader('Foo', 'bar');\nresponse.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);\n\nconst headerNames = response.getHeaderNames();\n// headerNames === ['foo', 'set-cookie']"}],"children":[]},{"kind":"method","id":"responsegetheaders","name":"getHeaders","title":"`response.getHeaders()`","scope":"module","overloadOf":null,"stability":null,"added":["v7.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":""}},"description":"Returns a shallow copy of the current outgoing headers. Since a shallow copy\nis used, array values may be mutated without additional calls to various\nheader-related http module methods. The keys of the returned object are the\nheader names and the values are the respective header values. All header names\nare lowercase.\n\nThe object returned by the `response.getHeaders()` method *does not*\nprototypically inherit from the JavaScript `Object`. This means that typical\n`Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`, and others\nare not defined and *will not work*.\n\n```js\nresponse.setHeader('Foo', 'bar');\nresponse.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);\n\nconst headers = response.getHeaders();\n// headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }\n```","summary":"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.","examples":[{"language":"js","displayName":null,"code":"response.setHeader('Foo', 'bar');\nresponse.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);\n\nconst headers = response.getHeaders();\n// headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }"}],"children":[]},{"kind":"method","id":"responsehasheadername","name":"hasHeader","title":"`response.hasHeader(name)`","scope":"module","overloadOf":null,"stability":null,"added":["v7.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":""}},"description":"Returns `true` if the header identified by `name` is currently set in the\noutgoing headers. The header name matching is case-insensitive.\n\n```js\nconst hasContentType = response.hasHeader('content-type');\n```","summary":"Returns `true` if the header identified by `name` is currently set in the outgoing headers. The header name matching is case-insensitive.","examples":[{"language":"js","displayName":null,"code":"const hasContentType = response.hasHeader('content-type');"}],"children":[]},{"kind":"property","id":"responseheaderssent","name":"headersSent","title":"`response.headersSent`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.3"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Boolean (read-only). True if headers were sent, false otherwise.","summary":"Boolean (read-only). True if headers were sent, false otherwise.","examples":[],"children":[]},{"kind":"method","id":"responseremoveheadername","name":"removeHeader","title":"`response.removeHeader(name)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Removes a header that's queued for implicit sending.\n\n```js\nresponse.removeHeader('Content-Encoding');\n```","summary":"Removes a header that's queued for implicit sending.","examples":[{"language":"js","displayName":null,"code":"response.removeHeader('Content-Encoding');"}],"children":[]},{"kind":"property","id":"responsereq","name":"req","title":"`response.req`","scope":"module","overloadOf":null,"stability":null,"added":["v15.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"http.IncomingMessage","links":[{"name":"http.IncomingMessage","href":"http.html#class-httpincomingmessage","start":0,"end":20}]},"default":null,"description":"A reference to the original HTTP `request` object.","summary":"A reference to the original HTTP `request` object.","examples":[],"children":[]},{"kind":"property","id":"responsesenddate","name":"sendDate","title":"`response.sendDate`","scope":"module","overloadOf":null,"stability":null,"added":["v0.7.5"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"When true, the Date header will be automatically generated and sent in\nthe response if it is not already present in the headers. Defaults to true.\n\nThis should only be disabled for testing; the Date header is required in\nmost HTTP responses (see [RFC 9110 Section 6.6.1](https://www.rfc-editor.org/rfc/rfc9110#section-6.6.1) for details).","summary":"When true, the Date header will be automatically generated and sent in the response if it is not already present in the headers. Defaults to true.","examples":[],"children":[]},{"kind":"method","id":"responsesetheadername-value","name":"setHeader","title":"`response.setHeader(name, value)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"value","type":{"text":"number | string | string[]","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":9,"end":15},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":18,"end":24}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"http.ServerResponse","links":[{"name":"http.ServerResponse","href":"http.html#class-httpserverresponse","start":0,"end":19}]},"description":""}},"description":"Returns the response object.\n\nSets a single header value for implicit headers. If this header already exists\nin the to-be-sent headers, its value will be replaced. Use an array of strings\nhere to send multiple headers with the same name. Non-string values will be\nstored without modification. Therefore, [`response.getHeader()`](#responsegetheadername) may return\nnon-string values. However, the non-string values will be converted to strings\nfor network transmission. The same response object is returned to the caller,\nto enable call chaining.\n\n```js\nresponse.setHeader('Content-Type', 'text/html');\n```\n\nor\n\n```js\nresponse.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']);\n```\n\nAttempting to set a header field name or value that contains invalid characters\nwill result in a [`TypeError`](errors.html#class-typeerror) being thrown.\n\nWhen headers have been set with [`response.setHeader()`](#responsesetheadername-value), they will be merged\nwith any headers passed to [`response.writeHead()`](#responsewriteheadstatuscode-statusmessage-headers), with the headers passed\nto [`response.writeHead()`](#responsewriteheadstatuscode-statusmessage-headers) given precedence.\n\n```js\n// Returns content-type = text/plain\nconst server = http.createServer((req, res) => {\n  res.setHeader('Content-Type', 'text/html');\n  res.setHeader('X-Foo', 'bar');\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('ok');\n});\n```\n\nIf [`response.writeHead()`](#responsewriteheadstatuscode-statusmessage-headers) method is called and this method has not been\ncalled, it will directly write the supplied header values onto the network\nchannel without caching internally, and the [`response.getHeader()`](#responsegetheadername) on the\nheader will not yield the expected result. If progressive population of headers\nis desired with potential future retrieval and modification, use\n[`response.setHeader()`](#responsesetheadername-value) instead of [`response.writeHead()`](#responsewriteheadstatuscode-statusmessage-headers).","summary":"Returns the response object.","examples":[{"language":"js","displayName":null,"code":"response.setHeader('Content-Type', 'text/html');"},{"language":"js","displayName":null,"code":"response.setHeader('Set-Cookie', ['type=ninja', 'language=javascript']);"},{"language":"js","displayName":null,"code":"// Returns content-type = text/plain\nconst server = http.createServer((req, res) => {\n  res.setHeader('Content-Type', 'text/html');\n  res.setHeader('X-Foo', 'bar');\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('ok');\n});"}],"children":[]},{"kind":"method","id":"responsesettimeoutmsecs-callback","name":"setTimeout","title":"`response.setTimeout(msecs[, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.12"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"msecs","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"http.ServerResponse","links":[{"name":"http.ServerResponse","href":"http.html#class-httpserverresponse","start":0,"end":19}]},"description":""}},"description":"Sets the Socket's timeout value to `msecs`. If a callback is\nprovided, then it is added as a listener on the `'timeout'` event on\nthe response object.\n\nIf no `'timeout'` listener is added to the request, the response, or\nthe server, then sockets are destroyed when they time out. If a handler is\nassigned to the request, the response, or the server's `'timeout'` events,\ntimed out sockets must be handled explicitly.","summary":"Sets the Socket's timeout value to `msecs`. If a callback is provided, then it is added as a listener on the `'timeout'` event on the response object.","examples":[],"children":[]},{"kind":"property","id":"responsesocket","name":"socket","title":"`response.socket`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"default":null,"description":"Reference to the underlying socket. Usually users will not want to access\nthis property. In particular, the socket will not emit `'readable'` events\nbecause of how the protocol parser attaches to the socket. After\n`response.end()`, the property is nulled.\n\n```mjs\nimport http from 'node:http';\nconst server = http.createServer((req, res) => {\n  const ip = res.socket.remoteAddress;\n  const port = res.socket.remotePort;\n  res.end(`Your IP address is ${ip} and your source port is ${port}.`);\n}).listen(3000);\n```\n\n```cjs\nconst http = require('node:http');\nconst server = http.createServer((req, res) => {\n  const ip = res.socket.remoteAddress;\n  const port = res.socket.remotePort;\n  res.end(`Your IP address is ${ip} and your source port is ${port}.`);\n}).listen(3000);\n```\n\nThis property is guaranteed to be an instance of the {net.Socket} class,\na subclass of {stream.Duplex}, unless the user specified a socket\ntype other than {net.Socket}.","summary":"Reference to the underlying socket. Usually users will not want to access this property. In particular, the socket will not emit `'readable'` events because of how the protocol parser attaches to the socket. After `response.end()`, the property is nulled.","examples":[{"language":"mjs","displayName":null,"code":"import http from 'node:http';\nconst server = http.createServer((req, res) => {\n  const ip = res.socket.remoteAddress;\n  const port = res.socket.remotePort;\n  res.end(`Your IP address is ${ip} and your source port is ${port}.`);\n}).listen(3000);"},{"language":"cjs","displayName":null,"code":"const http = require('node:http');\nconst server = http.createServer((req, res) => {\n  const ip = res.socket.remoteAddress;\n  const port = res.socket.remotePort;\n  res.end(`Your IP address is ${ip} and your source port is ${port}.`);\n}).listen(3000);"}],"children":[]},{"kind":"property","id":"responsestatuscode","name":"statusCode","title":"`response.statusCode`","scope":"module","overloadOf":null,"stability":null,"added":["v0.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":"200","description":"When using implicit headers (not calling [`response.writeHead()`](#responsewriteheadstatuscode-statusmessage-headers) explicitly),\nthis property controls the status code that will be sent to the client when\nthe headers get flushed.\n\n```js\nresponse.statusCode = 404;\n```\n\nAfter response header was sent to the client, this property indicates the\nstatus code which was sent out.","summary":"When using implicit headers (not calling `response.writeHead()` explicitly), this property controls the status code that will be sent to the client when the headers get flushed.","examples":[{"language":"js","displayName":null,"code":"response.statusCode = 404;"}],"children":[]},{"kind":"property","id":"responsestatusmessage","name":"statusMessage","title":"`response.statusMessage`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.8"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"When using implicit headers (not calling [`response.writeHead()`](#responsewriteheadstatuscode-statusmessage-headers) explicitly),\nthis property controls the status message that will be sent to the client when\nthe headers get flushed. If this is left as `undefined` then the standard\nmessage for the status code will be used.\n\n```js\nresponse.statusMessage = 'Not found';\n```\n\nAfter response header was sent to the client, this property indicates the\nstatus message which was sent out.","summary":"When using implicit headers (not calling `response.writeHead()` explicitly), this property controls the status message that will be sent to the client when the headers get flushed. If this is left as `undefined` then the standard message for the status code will be used.","examples":[{"language":"js","displayName":null,"code":"response.statusMessage = 'Not found';"}],"children":[]},{"kind":"property","id":"responsestrictcontentlength","name":"strictContentLength","title":"`response.strictContentLength`","scope":"module","overloadOf":null,"stability":null,"added":["v18.10.0","v16.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":"false","description":"If set to `true`, Node.js will check whether the `Content-Length`\nheader value and the size of the body, in bytes, are equal.\nMismatching the `Content-Length` header value will result\nin an `Error` being thrown, identified by `code:` [`'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`](errors.html#err_http_content_length_mismatch).","summary":"If set to `true`, Node.js will check whether the `Content-Length` header value and the size of the body, in bytes, are equal. Mismatching the `Content-Length` header value will result in an `Error` being thrown, identified by `code:` `'ERR_HTTP_CONTENT_LENGTH_MISMATCH'`.","examples":[],"children":[]},{"kind":"method","id":"responseuncork","name":"uncork","title":"`response.uncork()`","scope":"module","overloadOf":null,"stability":null,"added":["v13.2.0","v12.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"See [`writable.uncork()`](stream.html#writableuncork).","summary":"See `writable.uncork()`.","examples":[],"children":[]},{"kind":"property","id":"responsewritableended","name":"writableEnded","title":"`response.writableEnded`","scope":"module","overloadOf":null,"stability":null,"added":["v12.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Is `true` after [`response.end()`](#responseenddata-encoding-callback) has been called. This property\ndoes not indicate whether the data has been flushed, for this use\n[`response.writableFinished`](#responsewritablefinished) instead.","summary":"Is `true` after `response.end()` has been called. This property does not indicate whether the data has been flushed, for this use `response.writableFinished` instead.","examples":[],"children":[]},{"kind":"property","id":"responsewritablefinished","name":"writableFinished","title":"`response.writableFinished`","scope":"module","overloadOf":null,"stability":null,"added":["v12.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Is `true` if all data has been flushed to the underlying system, immediately\nbefore the [`'finish'`](#event-finish) event is emitted.","summary":"Is `true` if all data has been flushed to the underlying system, immediately before the `'finish'` event is emitted.","examples":[],"children":[]},{"kind":"method","id":"responsewritechunk-encoding-callback","name":"write","title":"`response.write(chunk[, encoding][, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.29"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.0.0"],"prUrl":"https://github.com/nodejs/node/pull/33155","commit":null,"description":"The `chunk` parameter can now be a `Uint8Array`."}],"signature":{"parameters":[{"name":"chunk","type":{"text":"string | Buffer | Uint8Array","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"Buffer","href":"buffer.html#class-buffer","start":9,"end":15},{"name":"Uint8Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array","start":18,"end":28}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"encoding","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":"'utf8'","optional":true,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":""}},"description":"If this method is called and [`response.writeHead()`](#responsewriteheadstatuscode-statusmessage-headers) has not been called,\nit will switch to implicit header mode and flush the implicit headers.\n\nThis sends a chunk of the response body. This method may\nbe called multiple times to provide successive parts of the body.\n\nIf `rejectNonStandardBodyWrites` is set to true in `createServer`\nthen writing to the body is not allowed when the request method or response\nstatus do not support content. If an attempt is made to write to the body for a\nHEAD request or as part of a `204` or `304`response, a synchronous `Error`\nwith the code `ERR_HTTP_BODY_NOT_ALLOWED` is thrown.\n\n`chunk` can be a string or a buffer. If `chunk` is a string,\nthe second parameter specifies how to encode it into a byte stream.\n`callback` will be called when this chunk of data is flushed.\n\nThis is the raw HTTP body and has nothing to do with higher-level multi-part\nbody encodings that may be used.\n\nThe first time [`response.write()`](#responsewritechunk-encoding-callback) is called, it will send the buffered\nheader information and the first chunk of the body to the client. The second\ntime [`response.write()`](#responsewritechunk-encoding-callback) is called, Node.js assumes data will be streamed,\nand sends the new data separately. That is, the response is buffered up to the\nfirst chunk of the body.\n\nReturns `true` if the entire data was flushed successfully to the kernel\nbuffer. Returns `false` if all or part of the data was queued in user memory.\n`'drain'` will be emitted when the buffer is free again.","summary":"If this method is called and `response.writeHead()` has not been called, it will switch to implicit header mode and flush the implicit headers.","examples":[],"children":[]},{"kind":"method","id":"responsewritecontinue","name":"writeContinue","title":"`response.writeContinue()`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Sends an HTTP/1.1 100 Continue message to the client, indicating that\nthe request body should be sent. See the [`'checkContinue'`](#event-checkcontinue) event on\n`Server`.","summary":"Sends an HTTP/1.1 100 Continue message to the client, indicating that the request body should be sent. See the `'checkContinue'` event on `Server`.","examples":[],"children":[]},{"kind":"method","id":"responsewriteearlyhintshints-callback","name":"writeEarlyHints","title":"`response.writeEarlyHints(hints[, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v18.11.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v18.11.0"],"prUrl":"https://github.com/nodejs/node/pull/44820","commit":null,"description":"Allow passing hints as an object."}],"signature":{"parameters":[{"name":"hints","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Sends an HTTP/1.1 103 Early Hints message to the client with a Link header,\nindicating that the user agent can preload/preconnect the linked resources.\nThe `hints` is an object containing the values of headers to be sent with\nearly hints message. The optional `callback` argument will be called when\nthe response message has been written.\n\n**Example**\n\n```js\nconst earlyHintsLink = '</styles.css>; rel=preload; as=style';\nresponse.writeEarlyHints({\n  'link': earlyHintsLink,\n});\n\nconst earlyHintsLinks = [\n  '</styles.css>; rel=preload; as=style',\n  '</scripts.js>; rel=preload; as=script',\n];\nresponse.writeEarlyHints({\n  'link': earlyHintsLinks,\n  'x-trace-id': 'id for diagnostics',\n});\n\nconst earlyHintsCallback = () => console.log('early hints message sent');\nresponse.writeEarlyHints({\n  'link': earlyHintsLinks,\n}, earlyHintsCallback);\n```","summary":"Sends an HTTP/1.1 103 Early Hints message to the client with a Link header, indicating that the user agent can preload/preconnect the linked resources. The `hints` is an object containing the values of headers to be sent with early hints message. The optional `callback` argument will be called when the response message has been written.","examples":[{"language":"js","displayName":null,"code":"const earlyHintsLink = '</styles.css>; rel=preload; as=style';\nresponse.writeEarlyHints({\n  'link': earlyHintsLink,\n});\n\nconst earlyHintsLinks = [\n  '</styles.css>; rel=preload; as=style',\n  '</scripts.js>; rel=preload; as=script',\n];\nresponse.writeEarlyHints({\n  'link': earlyHintsLinks,\n  'x-trace-id': 'id for diagnostics',\n});\n\nconst earlyHintsCallback = () => console.log('early hints message sent');\nresponse.writeEarlyHints({\n  'link': earlyHintsLinks,\n}, earlyHintsCallback);"}],"children":[]},{"kind":"method","id":"responsewriteheadstatuscode-statusmessage-headers","name":"writeHead","title":"`response.writeHead(statusCode[, statusMessage][, headers])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.30"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v14.14.0"],"prUrl":"https://github.com/nodejs/node/pull/35274","commit":null,"description":"Allow passing headers as an array."},{"versions":["v11.10.0","v10.17.0"],"prUrl":"https://github.com/nodejs/node/pull/25974","commit":null,"description":"Return `this` from `writeHead()` to allow chaining with `end()`."},{"versions":["v5.11.0","v4.4.5"],"prUrl":"https://github.com/nodejs/node/pull/6291","commit":null,"description":"A `RangeError` is thrown if `statusCode` is not a number in the range `[100, 999]`."}],"signature":{"parameters":[{"name":"statusCode","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"statusMessage","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]},{"name":"headers","type":{"text":"Object | Array","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6},{"name":"Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array","start":9,"end":14}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"http.ServerResponse","links":[{"name":"http.ServerResponse","href":"http.html#class-httpserverresponse","start":0,"end":19}]},"description":""}},"description":"Sends a response header to the request. The status code is a 3-digit HTTP\nstatus code, like `404`. The last argument, `headers`, are the response headers.\nOptionally one can give a human-readable `statusMessage` as the second\nargument.\n\n`headers` may be an `Array` where the keys and values are in the same list.\nIt is *not* a list of tuples. So, the even-numbered offsets are key values,\nand the odd-numbered offsets are the associated values. The array is in the same\nformat as `request.rawHeaders`.\n\nReturns a reference to the `ServerResponse`, so that calls can be chained.\n\n```js\nconst body = 'hello world';\nresponse\n  .writeHead(200, {\n    'Content-Length': Buffer.byteLength(body),\n    'Content-Type': 'text/plain',\n  })\n  .end(body);\n```\n\nThis method must only be called once on a message and it must\nbe called before [`response.end()`](#responseenddata-encoding-callback) is called.\n\nIf [`response.write()`](#responsewritechunk-encoding-callback) or [`response.end()`](#responseenddata-encoding-callback) are called before calling\nthis, the implicit/mutable headers will be calculated and call this function.\n\nWhen headers have been set with [`response.setHeader()`](#responsesetheadername-value), they will be merged\nwith any headers passed to [`response.writeHead()`](#responsewriteheadstatuscode-statusmessage-headers), with the headers passed\nto [`response.writeHead()`](#responsewriteheadstatuscode-statusmessage-headers) given precedence.\n\nIf this method is called and [`response.setHeader()`](#responsesetheadername-value) has not been called,\nit will directly write the supplied header values onto the network channel\nwithout caching internally, and the [`response.getHeader()`](#responsegetheadername) on the header\nwill not yield the expected result. If progressive population of headers is\ndesired with potential future retrieval and modification, use\n[`response.setHeader()`](#responsesetheadername-value) instead.\n\n```js\n// Returns content-type = text/plain\nconst server = http.createServer((req, res) => {\n  res.setHeader('Content-Type', 'text/html');\n  res.setHeader('X-Foo', 'bar');\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('ok');\n});\n```\n\n`Content-Length` is read in bytes, not characters. Use\n[`Buffer.byteLength()`](buffer.html#static-method-bufferbytelengthstring-encoding) to determine the length of the body in bytes. Node.js\nwill check whether `Content-Length` and the length of the body which has\nbeen transmitted are equal or not.\n\nAttempting to set a header field name or value that contains invalid characters\nwill result in a [`TypeError`](errors.html#class-typeerror) being thrown.","summary":"Sends a response header to the request. The status code is a 3-digit HTTP status code, like `404`. The last argument, `headers`, are the response headers. Optionally one can give a human-readable `statusMessage` as the second argument.","examples":[{"language":"js","displayName":null,"code":"const body = 'hello world';\nresponse\n  .writeHead(200, {\n    'Content-Length': Buffer.byteLength(body),\n    'Content-Type': 'text/plain',\n  })\n  .end(body);"},{"language":"js","displayName":null,"code":"// Returns content-type = text/plain\nconst server = http.createServer((req, res) => {\n  res.setHeader('Content-Type', 'text/html');\n  res.setHeader('X-Foo', 'bar');\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('ok');\n});"}],"children":[]},{"kind":"method","id":"responsewriteinformationstatuscode-headers-callback","name":"writeInformation","title":"`response.writeInformation(statusCode[, headers][, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v26.2.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"statusCode","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"An HTTP 1xx informational status code, between `100`\nand `199` inclusive, excluding `101` (Switching Protocols) which is only\navailable through the [`'upgrade'`](#event-upgrade) event.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"headers","type":{"text":"Object | Array","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6},{"name":"Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array","start":9,"end":14}]},"description":"An optional set of headers to send with the\ninformational response. Accepts the same shapes as\n[`response.writeHead()`](#responsewriteheadstatuscode-statusmessage-headers).","default":null,"optional":true,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Optional, called once the message has been written\nto the socket.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Sends an arbitrary HTTP/1.1 1xx informational response to the client. This\nis a generic equivalent of [`response.writeContinue()`](#responsewritecontinue),\n[`response.writeProcessing()`](#responsewriteprocessing) and [`response.writeEarlyHints()`](#responsewriteearlyhintshints-callback), and\ncan be called multiple times before the final response. After the final\nresponse headers have been sent (via [`response.writeHead()`](#responsewriteheadstatuscode-statusmessage-headers) or an\nimplicit header), calling this method throws `ERR_HTTP_HEADERS_SENT`.\n\nClients receive these responses via the [`'information'`](#event-information)\nevent on `http.ClientRequest`.\n\n```js\nresponse.writeInformation(110, { 'X-Progress': '50%' });\n```","summary":"Sends an arbitrary HTTP/1.1 1xx informational response to the client. This is a generic equivalent of `response.writeContinue()`, `response.writeProcessing()` and `response.writeEarlyHints()`, and can be called multiple times before the final response. After the final response headers have been sent (via `response.writeHead()` or an implicit header), calling this method throws `ERR_HTTP_HEADERS_SENT`.","examples":[{"language":"js","displayName":null,"code":"response.writeInformation(110, { 'X-Progress': '50%' });"}],"children":[]},{"kind":"method","id":"responsewriteprocessing","name":"writeProcessing","title":"`response.writeProcessing()`","scope":"module","overloadOf":null,"stability":null,"added":["v10.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Sends an HTTP/1.1 102 Processing message to the client, indicating that\nthe request body should be sent.","summary":"Sends an HTTP/1.1 102 Processing message to the client, indicating that the request body should be sent.","examples":[],"children":[]}]},{"kind":"class","id":"class-httpincomingmessage","name":"IncomingMessage","title":"Class: `http.IncomingMessage`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.17"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.5.0"],"prUrl":"https://github.com/nodejs/node/pull/33035","commit":null,"description":"The `destroyed` value returns `true` after the incoming data is consumed."},{"versions":["v13.1.0","v12.16.0"],"prUrl":"https://github.com/nodejs/node/pull/30135","commit":null,"description":"The `readableHighWaterMark` value mirrors that of the socket."}],"extends":{"text":"stream.Readable","links":[{"name":"stream.Readable","href":"stream.html#class-streamreadable","start":0,"end":15}]},"description":"An `IncomingMessage` object is created by [`http.Server`](#class-httpserver) or\n[`http.ClientRequest`](#class-httpclientrequest) and passed as the first argument to the [`'request'`](#event-request)\nand [`'response'`](#event-response) event respectively. It may be used to access response\nstatus, headers, and data.\n\nDifferent from its `socket` value which is a subclass of {stream.Duplex}, the\n`IncomingMessage` itself extends {stream.Readable} and is created separately to\nparse and emit the incoming HTTP headers and payload, as the underlying socket\nmay be reused multiple times in case of keep-alive.","summary":"An `IncomingMessage` object is created by `http.Server` or `http.ClientRequest` and passed as the first argument to the `'request'` and `'response'` event respectively. It may be used to access response status, headers, and data.","examples":[],"children":[{"kind":"event","id":"event-aborted","name":"aborted","title":"Event: `'aborted'`","scope":"module","overloadOf":null,"stability":{"index":"0","description":"Deprecated. Listen for `'close'` event instead."},"added":["v0.3.8"],"deprecated":["v17.0.0","v16.12.0"],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Emitted when the request has been aborted.","summary":"Emitted when the request has been aborted.","examples":[],"children":[]},{"kind":"event","id":"event-close-3","name":"close","title":"Event: `'close'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.4.2"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v16.0.0"],"prUrl":"https://github.com/nodejs/node/pull/33035","commit":null,"description":"The close event is now emitted when the request has been completed and not when the underlying socket is closed."}],"parameters":[],"description":"Emitted when the request has been completed.","summary":"Emitted when the request has been completed.","examples":[],"children":[]},{"kind":"property","id":"messageaborted","name":"aborted","title":"`message.aborted`","scope":"module","overloadOf":null,"stability":{"index":"0","description":"Deprecated. Check `message.destroyed` from {stream.Readable}."},"added":["v10.1.0"],"deprecated":["v17.0.0","v16.12.0"],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"The `message.aborted` property will be `true` if the request has\nbeen aborted.","summary":"The `message.aborted` property will be `true` if the request has been aborted.","examples":[],"children":[]},{"kind":"property","id":"messagecomplete","name":"complete","title":"`message.complete`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"The `message.complete` property will be `true` if a complete HTTP message has\nbeen received and successfully parsed.\n\nThis property is particularly useful as a means of determining if a client or\nserver fully transmitted a message before a connection was terminated:\n\n```js\nconst req = http.request({\n  host: '127.0.0.1',\n  port: 8080,\n  method: 'POST',\n}, (res) => {\n  res.resume();\n  res.on('end', () => {\n    if (!res.complete)\n      console.error(\n        'The connection was terminated while the message was still being sent');\n  });\n});\n```","summary":"The `message.complete` property will be `true` if a complete HTTP message has been received and successfully parsed.","examples":[{"language":"js","displayName":null,"code":"const req = http.request({\n  host: '127.0.0.1',\n  port: 8080,\n  method: 'POST',\n}, (res) => {\n  res.resume();\n  res.on('end', () => {\n    if (!res.complete)\n      console.error(\n        'The connection was terminated while the message was still being sent');\n  });\n});"}],"children":[]},{"kind":"property","id":"messageconnection","name":"connection","title":"`message.connection`","scope":"module","overloadOf":null,"stability":{"index":"0","description":"Deprecated. Use [`message.socket`](#messagesocket)."},"added":["v0.1.90"],"deprecated":["v16.0.0"],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"Alias for [`message.socket`](#messagesocket).","summary":"Alias for `message.socket`.","examples":[],"children":[]},{"kind":"method","id":"messagedestroyerror","name":"destroy","title":"`message.destroy([error])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v14.5.0","v12.19.0"],"prUrl":"https://github.com/nodejs/node/pull/32789","commit":null,"description":"The function returns `this` for consistency with other Readable streams."}],"signature":{"parameters":[{"name":"error","type":{"text":"Error","links":[{"name":"Error","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error","start":0,"end":5}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"this","links":[{"name":"this","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/this","start":0,"end":4}]},"description":""}},"description":"Calls `destroy()` on the socket that received the `IncomingMessage`. If `error`\nis provided, an `'error'` event is emitted on the socket and `error` is passed\nas an argument to any listeners on the event.","summary":"Calls `destroy()` on the socket that received the `IncomingMessage`. If `error` is provided, an `'error'` event is emitted on the socket and `error` is passed as an argument to any listeners on the event.","examples":[],"children":[]},{"kind":"property","id":"messageheaders","name":"headers","title":"`message.headers`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.5"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v19.5.0","v18.14.0"],"prUrl":"https://github.com/nodejs/node/pull/45982","commit":null,"description":"The `joinDuplicateHeaders` option in the `http.request()` and `http.createServer()` functions ensures that duplicate headers are not discarded, but rather combined using a comma separator, in accordance with RFC 9110 Section 5.3."},{"versions":["v15.1.0"],"prUrl":"https://github.com/nodejs/node/pull/35281","commit":null,"description":"`message.headers` is now lazily computed using an accessor property on the prototype and is no longer enumerable."}],"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"default":null,"description":"The request/response headers object.\n\nKey-value pairs of header names and values. Header names are lower-cased.\n\n```js\n// Prints something like:\n//\n// { 'user-agent': 'curl/7.22.0',\n//   host: '127.0.0.1:8000',\n//   accept: '*/*' }\nconsole.log(request.headers);\n```\n\nDuplicates in raw headers are handled in the following ways, depending on the\nheader name:\n\n* Duplicates of `age`, `authorization`, `content-length`, `content-type`,\n  `etag`, `expires`, `from`, `host`, `if-modified-since`, `if-unmodified-since`,\n  `last-modified`, `location`, `max-forwards`, `proxy-authorization`, `referer`,\n  `retry-after`, `server`, or `user-agent` are discarded.\n  To allow duplicate values of the headers listed above to be joined,\n  use the option `joinDuplicateHeaders` in [`http.request()`](#httprequestoptions-callback)\n  and [`http.createServer()`](#httpcreateserveroptions-requestlistener). See RFC 9110 Section 5.3 for more\n  information.\n* `set-cookie` is always an array. Duplicates are added to the array.\n* For duplicate `cookie` headers, the values are joined together with `; `.\n* For all other headers, the values are joined together with `, `.","summary":"The request/response headers object.","examples":[{"language":"js","displayName":null,"code":"// Prints something like:\n//\n// { 'user-agent': 'curl/7.22.0',\n//   host: '127.0.0.1:8000',\n//   accept: '*/*' }\nconsole.log(request.headers);"}],"children":[]},{"kind":"property","id":"messageheadersdistinct","name":"headersDistinct","title":"`message.headersDistinct`","scope":"module","overloadOf":null,"stability":null,"added":["v18.3.0","v16.17.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"default":null,"description":"Similar to [`message.headers`](#messageheaders), but there is no join logic and the values are\nalways arrays of strings, even for headers received just once.\n\n```js\n// Prints something like:\n//\n// { 'user-agent': ['curl/7.22.0'],\n//   host: ['127.0.0.1:8000'],\n//   accept: ['*/*'] }\nconsole.log(request.headersDistinct);\n```","summary":"Similar to `message.headers`, but there is no join logic and the values are always arrays of strings, even for headers received just once.","examples":[{"language":"js","displayName":null,"code":"// Prints something like:\n//\n// { 'user-agent': ['curl/7.22.0'],\n//   host: ['127.0.0.1:8000'],\n//   accept: ['*/*'] }\nconsole.log(request.headersDistinct);"}],"children":[]},{"kind":"property","id":"messagehttpversion","name":"httpVersion","title":"`message.httpVersion`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"In case of server request, the HTTP version sent by the client. In the case of\nclient response, the HTTP version of the connected-to server.\nProbably either `'1.1'` or `'1.0'`.\n\nAlso `message.httpVersionMajor` is the first integer and\n`message.httpVersionMinor` is the second.","summary":"In case of server request, the HTTP version sent by the client. In the case of client response, the HTTP version of the connected-to server. Probably either `'1.1'` or `'1.0'`.","examples":[],"children":[]},{"kind":"property","id":"messagemethod","name":"method","title":"`message.method`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"**Only valid for request obtained from [`http.Server`](#class-httpserver).**\n\nThe request method as a string. Read only. Examples: `'GET'`, `'DELETE'`.","summary":"**Only valid for request obtained from `http.Server`.**","examples":[],"children":[]},{"kind":"property","id":"messagerawheaders","name":"rawHeaders","title":"`message.rawHeaders`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.6"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"The raw request/response headers list exactly as they were received.\n\nThe keys and values are in the same list. It is *not* a\nlist of tuples. So, the even-numbered offsets are key values, and the\nodd-numbered offsets are the associated values.\n\nHeader names are not lowercased, and duplicates are not merged.\n\n```js\n// Prints something like:\n//\n// [ 'user-agent',\n//   'this is invalid because there can be only one',\n//   'User-Agent',\n//   'curl/7.22.0',\n//   'Host',\n//   '127.0.0.1:8000',\n//   'ACCEPT',\n//   '*/*' ]\nconsole.log(request.rawHeaders);\n```","summary":"The raw request/response headers list exactly as they were received.","examples":[{"language":"js","displayName":null,"code":"// Prints something like:\n//\n// [ 'user-agent',\n//   'this is invalid because there can be only one',\n//   'User-Agent',\n//   'curl/7.22.0',\n//   'Host',\n//   '127.0.0.1:8000',\n//   'ACCEPT',\n//   '*/*' ]\nconsole.log(request.rawHeaders);"}],"children":[]},{"kind":"property","id":"messagerawtrailers","name":"rawTrailers","title":"`message.rawTrailers`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.6"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"The raw request/response trailer keys and values exactly as they were\nreceived. Only populated at the `'end'` event.","summary":"The raw request/response trailer keys and values exactly as they were received. Only populated at the `'end'` event.","examples":[],"children":[]},{"kind":"method","id":"messagesettimeoutmsecs-callback","name":"setTimeout","title":"`message.setTimeout(msecs[, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.9"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"msecs","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"http.IncomingMessage","links":[{"name":"http.IncomingMessage","href":"http.html#class-httpincomingmessage","start":0,"end":20}]},"description":""}},"description":"Calls `message.socket.setTimeout(msecs, callback)`.","summary":"Calls `message.socket.setTimeout(msecs, callback)`.","examples":[],"children":[]},{"kind":"property","id":"messagesignal","name":"signal","title":"`message.signal`","scope":"module","overloadOf":null,"stability":null,"added":["v26.1.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v26.7.0"],"prUrl":"https://github.com/nodejs/node/pull/64392","commit":null,"description":"The signal is no longer aborted after the message completes normally."}],"type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"default":null,"description":"An {AbortSignal} that is aborted when the message is destroyed before\ncompletion or when its underlying socket closes before request handling or\nresponse reading completes.\nThe signal is created lazily on first access — no {AbortController} is allocated\nfor requests that never use this property.\n\nThis is useful for cancelling downstream asynchronous work such as database\nqueries or `fetch` calls when a client disconnects mid-request.\n\n```mjs\nimport http from 'node:http';\n\nhttp.createServer(async (req, res) => {\n  try {\n    const data = await fetch('https://example.com/api', { signal: req.signal });\n    res.end(JSON.stringify(await data.json()));\n  } catch (err) {\n    if (err.name === 'AbortError') return;\n    res.statusCode = 500;\n    res.end('Internal Server Error');\n  }\n}).listen(3000);\n```\n\n```cjs\nconst http = require('node:http');\n\nhttp.createServer(async (req, res) => {\n  try {\n    const data = await fetch('https://example.com/api', { signal: req.signal });\n    res.end(JSON.stringify(await data.json()));\n  } catch (err) {\n    if (err.name === 'AbortError') return;\n    res.statusCode = 500;\n    res.end('Internal Server Error');\n  }\n}).listen(3000);\n```","summary":"An {AbortSignal} that is aborted when the message is destroyed before completion or when its underlying socket closes before request handling or response reading completes. The signal is created lazily on first access — no {AbortController} is allocated for requests that never use this property.","examples":[{"language":"mjs","displayName":null,"code":"import http from 'node:http';\n\nhttp.createServer(async (req, res) => {\n  try {\n    const data = await fetch('https://example.com/api', { signal: req.signal });\n    res.end(JSON.stringify(await data.json()));\n  } catch (err) {\n    if (err.name === 'AbortError') return;\n    res.statusCode = 500;\n    res.end('Internal Server Error');\n  }\n}).listen(3000);"},{"language":"cjs","displayName":null,"code":"const http = require('node:http');\n\nhttp.createServer(async (req, res) => {\n  try {\n    const data = await fetch('https://example.com/api', { signal: req.signal });\n    res.end(JSON.stringify(await data.json()));\n  } catch (err) {\n    if (err.name === 'AbortError') return;\n    res.statusCode = 500;\n    res.end('Internal Server Error');\n  }\n}).listen(3000);"}],"children":[]},{"kind":"property","id":"messagesocket","name":"socket","title":"`message.socket`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"default":null,"description":"The [`net.Socket`](net.html#class-netsocket) object associated with the connection.\n\nWith HTTPS support, use [`request.socket.getPeerCertificate()`](tls.html#tlssocketgetpeercertificatedetailed) to obtain the\nclient's authentication details.\n\nThis property is guaranteed to be an instance of the {net.Socket} class,\na subclass of {stream.Duplex}, unless the user specified a socket\ntype other than {net.Socket} or internally nulled.","summary":"The `net.Socket` object associated with the connection.","examples":[],"children":[]},{"kind":"property","id":"messagestatuscode","name":"statusCode","title":"`message.statusCode`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.1"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"**Only valid for response obtained from [`http.ClientRequest`](#class-httpclientrequest).**\n\nThe 3-digit HTTP response status code. E.G. `404`.","summary":"**Only valid for response obtained from `http.ClientRequest`.**","examples":[],"children":[]},{"kind":"property","id":"messagestatusmessage","name":"statusMessage","title":"`message.statusMessage`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.10"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"**Only valid for response obtained from [`http.ClientRequest`](#class-httpclientrequest).**\n\nThe HTTP response status message (reason phrase). E.G. `OK` or `Internal Server\nError`.","summary":"**Only valid for response obtained from `http.ClientRequest`.**","examples":[],"children":[]},{"kind":"property","id":"messagetrailers","name":"trailers","title":"`message.trailers`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"default":null,"description":"The request/response trailers object. Only populated at the `'end'` event.","summary":"The request/response trailers object. Only populated at the `'end'` event.","examples":[],"children":[]},{"kind":"property","id":"messagetrailersdistinct","name":"trailersDistinct","title":"`message.trailersDistinct`","scope":"module","overloadOf":null,"stability":null,"added":["v18.3.0","v16.17.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"default":null,"description":"Similar to [`message.trailers`](#messagetrailers), but there is no join logic and the values are\nalways arrays of strings, even for headers received just once.\nOnly populated at the `'end'` event.","summary":"Similar to `message.trailers`, but there is no join logic and the values are always arrays of strings, even for headers received just once. Only populated at the `'end'` event.","examples":[],"children":[]},{"kind":"property","id":"messageurl","name":"url","title":"`message.url`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"**Only valid for request obtained from [`http.Server`](#class-httpserver).**\n\nRequest URL string. This contains only the URL that is present in the actual\nHTTP request. Take the following request:\n\n```http\nGET /status?name=ryan HTTP/1.1\nAccept: text/plain\n```\n\nTo parse the URL into its parts:\n\n```js\nnew URL(`http://${process.env.HOST ?? 'localhost'}${request.url}`);\n```\n\nWhen `request.url` is `'/status?name=ryan'` and `process.env.HOST` is undefined:\n\n```console\n$ node\n> new URL(`http://${process.env.HOST ?? 'localhost'}${request.url}`);\nURL {\n  href: 'http://localhost/status?name=ryan',\n  origin: 'http://localhost',\n  protocol: 'http:',\n  username: '',\n  password: '',\n  host: 'localhost',\n  hostname: 'localhost',\n  port: '',\n  pathname: '/status',\n  search: '?name=ryan',\n  searchParams: URLSearchParams { 'name' => 'ryan' },\n  hash: ''\n}\n```\n\nEnsure that you set `process.env.HOST` to the server's host name, or consider\nreplacing this part entirely. If using `req.headers.host`, ensure proper\nvalidation is used, as clients may specify a custom `Host` header.","summary":"**Only valid for request obtained from `http.Server`.**","examples":[{"language":"http","displayName":null,"code":"GET /status?name=ryan HTTP/1.1\nAccept: text/plain"},{"language":"js","displayName":null,"code":"new URL(`http://${process.env.HOST ?? 'localhost'}${request.url}`);"},{"language":"console","displayName":null,"code":"$ node\n> new URL(`http://${process.env.HOST ?? 'localhost'}${request.url}`);\nURL {\n  href: 'http://localhost/status?name=ryan',\n  origin: 'http://localhost',\n  protocol: 'http:',\n  username: '',\n  password: '',\n  host: 'localhost',\n  hostname: 'localhost',\n  port: '',\n  pathname: '/status',\n  search: '?name=ryan',\n  searchParams: URLSearchParams { 'name' => 'ryan' },\n  hash: ''\n}"}],"children":[]}]},{"kind":"class","id":"class-httpoutgoingmessage","name":"OutgoingMessage","title":"Class: `http.OutgoingMessage`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.17"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":{"text":"Stream","links":[{"name":"Stream","href":"stream.html#stream","start":0,"end":6}]},"description":"This class serves as the parent class of [`http.ClientRequest`](#class-httpclientrequest)\nand [`http.ServerResponse`](#class-httpserverresponse). It is an abstract outgoing message from\nthe perspective of the participants of an HTTP transaction.","summary":"This class serves as the parent class of `http.ClientRequest` and `http.ServerResponse`. It is an abstract outgoing message from the perspective of the participants of an HTTP transaction.","examples":[],"children":[{"kind":"event","id":"event-drain","name":"drain","title":"Event: `'drain'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.6"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Emitted when the buffer of the message is free again.","summary":"Emitted when the buffer of the message is free again.","examples":[],"children":[]},{"kind":"event","id":"event-finish-2","name":"finish","title":"Event: `'finish'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.17"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Emitted when the transmission is finished successfully.","summary":"Emitted when the transmission is finished successfully.","examples":[],"children":[]},{"kind":"event","id":"event-prefinish","name":"prefinish","title":"Event: `'prefinish'`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.6"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"parameters":[],"description":"Emitted after `outgoingMessage.end()` is called.\nWhen the event is emitted, all data has been processed but not necessarily\ncompletely flushed.","summary":"Emitted after `outgoingMessage.end()` is called. When the event is emitted, all data has been processed but not necessarily completely flushed.","examples":[],"children":[]},{"kind":"method","id":"outgoingmessageaddtrailersheaders","name":"addTrailers","title":"`outgoingMessage.addTrailers(headers)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"headers","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Adds HTTP trailers (headers but at the end of the message) to the message.\n\nTrailers will **only** be emitted if the message is chunked encoded. If not,\nthe trailers will be silently discarded.\n\nHTTP requires the `Trailer` header to be sent to emit trailers,\nwith a list of header field names in its value, e.g.\n\n```js\nmessage.writeHead(200, { 'Content-Type': 'text/plain',\n                         'Trailer': 'Content-MD5' });\nmessage.write(fileData);\nmessage.addTrailers({ 'Content-MD5': '7895bf4b8828b55ceaf47747b4bca667' });\nmessage.end();\n```\n\nAttempting to set a header field name or value that contains invalid characters\nwill result in a `TypeError` being thrown.","summary":"Adds HTTP trailers (headers but at the end of the message) to the message.","examples":[{"language":"js","displayName":null,"code":"message.writeHead(200, { 'Content-Type': 'text/plain',\n                         'Trailer': 'Content-MD5' });\nmessage.write(fileData);\nmessage.addTrailers({ 'Content-MD5': '7895bf4b8828b55ceaf47747b4bca667' });\nmessage.end();"}],"children":[]},{"kind":"method","id":"outgoingmessageappendheadername-value","name":"appendHeader","title":"`outgoingMessage.appendHeader(name, value)`","scope":"module","overloadOf":null,"stability":null,"added":["v18.3.0","v16.17.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Header name","default":null,"optional":false,"rest":false,"properties":[]},{"name":"value","type":{"text":"string | string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":9,"end":15}]},"description":"Header value","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"this","links":[{"name":"this","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/this","start":0,"end":4}]},"description":""}},"description":"Append a single header value to the header object.\n\nIf the value is an array, this is equivalent to calling this method multiple\ntimes.\n\nIf there were no previous values for the header, this is equivalent to calling\n[`outgoingMessage.setHeader(name, value)`](#outgoingmessagesetheadername-value).\n\nDepending of the value of `options.uniqueHeaders` when the client request or the\nserver were created, this will end up in the header being sent multiple times or\na single time with values joined using `; `.","summary":"Append a single header value to the header object.","examples":[],"children":[]},{"kind":"property","id":"outgoingmessageconnection","name":"connection","title":"`outgoingMessage.connection`","scope":"module","overloadOf":null,"stability":{"index":"0","description":"Deprecated: Use [`outgoingMessage.socket`](#outgoingmessagesocket) instead."},"added":["v0.3.0"],"deprecated":["v15.12.0","v14.17.1"],"removed":[],"napiVersion":[],"changes":[],"type":null,"default":null,"description":"Alias of [`outgoingMessage.socket`](#outgoingmessagesocket).","summary":"Alias of `outgoingMessage.socket`.","examples":[],"children":[]},{"kind":"method","id":"outgoingmessagecork","name":"cork","title":"`outgoingMessage.cork()`","scope":"module","overloadOf":null,"stability":null,"added":["v13.2.0","v12.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"See [`writable.cork()`](stream.html#writablecork).","summary":"See `writable.cork()`.","examples":[],"children":[]},{"kind":"method","id":"outgoingmessagedestroyerror","name":"destroy","title":"`outgoingMessage.destroy([error])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"error","type":{"text":"Error","links":[{"name":"Error","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Error","start":0,"end":5}]},"description":"Optional, an error to emit with `error` event","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"this","links":[{"name":"this","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/this","start":0,"end":4}]},"description":""}},"description":"Destroys the message. Once a socket is associated with the message\nand is connected, that socket will be destroyed as well.","summary":"Destroys the message. Once a socket is associated with the message and is connected, that socket will be destroyed as well.","examples":[],"children":[]},{"kind":"method","id":"outgoingmessageendchunk-encoding-callback","name":"end","title":"`outgoingMessage.end(chunk[, encoding][, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.90"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.0.0"],"prUrl":"https://github.com/nodejs/node/pull/33155","commit":null,"description":"The `chunk` parameter can now be a `Uint8Array`."},{"versions":["v0.11.6"],"prUrl":null,"commit":null,"description":"add `callback` argument."}],"signature":{"parameters":[{"name":"chunk","type":{"text":"string | Buffer | Uint8Array","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"Buffer","href":"buffer.html#class-buffer","start":9,"end":15},{"name":"Uint8Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array","start":18,"end":28}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"encoding","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Optional, **Default**: `utf8`","default":null,"optional":true,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Optional","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"this","links":[{"name":"this","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/this","start":0,"end":4}]},"description":""}},"description":"Finishes the outgoing message. If any parts of the body are unsent, it will\nflush them to the underlying system. If the message is chunked, it will\nsend the terminating chunk `0\\r\\n\\r\\n`, and send the trailers (if any).\n\nIf `chunk` is specified, it is equivalent to calling\n`outgoingMessage.write(chunk, encoding)`, followed by\n`outgoingMessage.end(callback)`.\n\nIf `callback` is provided, it will be called when the message is finished\n(equivalent to a listener of the `'finish'` event).","summary":"Finishes the outgoing message. If any parts of the body are unsent, it will flush them to the underlying system. If the message is chunked, it will send the terminating chunk `0\\r\\n\\r\\n`, and send the trailers (if any).","examples":[],"children":[]},{"kind":"method","id":"outgoingmessageflushheaders","name":"flushHeaders","title":"`outgoingMessage.flushHeaders()`","scope":"module","overloadOf":null,"stability":null,"added":["v1.6.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Flushes the message headers.\n\nFor efficiency reason, Node.js normally buffers the message headers\nuntil `outgoingMessage.end()` is called or the first chunk of message data\nis written. It then tries to pack the headers and data into a single TCP\npacket.\n\nIt is usually desired (it saves a TCP round-trip), but not when the first\ndata is not sent until possibly much later. `outgoingMessage.flushHeaders()`\nbypasses the optimization and kickstarts the message.","summary":"Flushes the message headers.","examples":[],"children":[]},{"kind":"method","id":"outgoingmessagegetheadername","name":"getHeader","title":"`outgoingMessage.getHeader(name)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Name of header","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"number | string | string[] | undefined","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":9,"end":15},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":18,"end":24},{"name":"undefined","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#undefined_type","start":29,"end":38}]},"description":""}},"description":"Gets the value of the HTTP header with the given name. If that header is not\nset, the returned value will be `undefined`.","summary":"Gets the value of the HTTP header with the given name. If that header is not set, the returned value will be `undefined`.","examples":[],"children":[]},{"kind":"method","id":"outgoingmessagegetheadernames","name":"getHeaderNames","title":"`outgoingMessage.getHeaderNames()`","scope":"module","overloadOf":null,"stability":null,"added":["v7.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":""}},"description":"Returns an array containing the unique names of the current outgoing headers.\nAll names are lowercase.","summary":"Returns an array containing the unique names of the current outgoing headers. All names are lowercase.","examples":[],"children":[]},{"kind":"method","id":"outgoingmessagegetheaders","name":"getHeaders","title":"`outgoingMessage.getHeaders()`","scope":"module","overloadOf":null,"stability":null,"added":["v7.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":{"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":""}},"description":"Returns a shallow copy of the current outgoing headers. Since a shallow\ncopy is used, array values may be mutated without additional calls to\nvarious header-related HTTP module methods. The keys of the returned\nobject are the header names and the values are the respective header\nvalues. All header names are lowercase.\n\nThe object returned by the `outgoingMessage.getHeaders()` method does\nnot prototypically inherit from the JavaScript `Object`. This means that\ntypical `Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`,\nand others are not defined and will not work.\n\n```js\noutgoingMessage.setHeader('Foo', 'bar');\noutgoingMessage.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);\n\nconst headers = outgoingMessage.getHeaders();\n// headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }\n```","summary":"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.","examples":[{"language":"js","displayName":null,"code":"outgoingMessage.setHeader('Foo', 'bar');\noutgoingMessage.setHeader('Set-Cookie', ['foo=bar', 'bar=baz']);\n\nconst headers = outgoingMessage.getHeaders();\n// headers === { foo: 'bar', 'set-cookie': ['foo=bar', 'bar=baz'] }"}],"children":[]},{"kind":"method","id":"outgoingmessagehasheadername","name":"hasHeader","title":"`outgoingMessage.hasHeader(name)`","scope":"module","overloadOf":null,"stability":null,"added":["v7.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":""}},"description":"Returns `true` if the header identified by `name` is currently set in the\noutgoing headers. The header name is case-insensitive.\n\n```js\nconst hasContentType = outgoingMessage.hasHeader('content-type');\n```","summary":"Returns `true` if the header identified by `name` is currently set in the outgoing headers. The header name is case-insensitive.","examples":[{"language":"js","displayName":null,"code":"const hasContentType = outgoingMessage.hasHeader('content-type');"}],"children":[]},{"kind":"property","id":"outgoingmessageheaderssent","name":"headersSent","title":"`outgoingMessage.headersSent`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.3"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Read-only. `true` if the headers were sent, otherwise `false`.","summary":"Read-only. `true` if the headers were sent, otherwise `false`.","examples":[],"children":[]},{"kind":"method","id":"outgoingmessagepipe","name":"pipe","title":"`outgoingMessage.pipe()`","scope":"module","overloadOf":null,"stability":null,"added":["v9.0.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"Overrides the `stream.pipe()` method inherited from the legacy `Stream` class\nwhich is the parent class of `http.OutgoingMessage`.\n\nCalling this method will throw an `Error` because `outgoingMessage` is a\nwrite-only stream.","summary":"Overrides the `stream.pipe()` method inherited from the legacy `Stream` class which is the parent class of `http.OutgoingMessage`.","examples":[],"children":[]},{"kind":"method","id":"outgoingmessageremoveheadername","name":"removeHeader","title":"`outgoingMessage.removeHeader(name)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Header name","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Removes a header that is queued for implicit sending.\n\n```js\noutgoingMessage.removeHeader('Content-Encoding');\n```","summary":"Removes a header that is queued for implicit sending.","examples":[{"language":"js","displayName":null,"code":"outgoingMessage.removeHeader('Content-Encoding');"}],"children":[]},{"kind":"method","id":"outgoingmessagesetheadername-value","name":"setHeader","title":"`outgoingMessage.setHeader(name, value)`","scope":"module","overloadOf":null,"stability":null,"added":["v0.4.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Header name","default":null,"optional":false,"rest":false,"properties":[]},{"name":"value","type":{"text":"number | string | string[]","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":9,"end":15},{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":18,"end":24}]},"description":"Header value","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"this","links":[{"name":"this","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/this","start":0,"end":4}]},"description":""}},"description":"Sets a single header value. If the header already exists in the to-be-sent\nheaders, its value will be replaced. Use an array of strings to send multiple\nheaders with the same name.","summary":"Sets a single header value. If the header already exists in the to-be-sent headers, its value will be replaced. Use an array of strings to send multiple headers with the same name.","examples":[],"children":[]},{"kind":"method","id":"outgoingmessagesetheadersheaders","name":"setHeaders","title":"`outgoingMessage.setHeaders(headers)`","scope":"module","overloadOf":null,"stability":null,"added":["v19.6.0","v18.15.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"headers","type":{"text":"Headers | Map","links":[{"name":"Headers","href":"https://developer.mozilla.org/docs/Web/API/Headers","start":0,"end":7},{"name":"Map","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Map","start":10,"end":13}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":{"type":{"text":"this","links":[{"name":"this","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/this","start":0,"end":4}]},"description":""}},"description":"Sets multiple header values for implicit headers.\n`headers` must be an instance of [`Headers`](globals.html#class-headers) or `Map`,\nif a header already exists in the to-be-sent headers,\nits value will be replaced.\n\n```js\nconst headers = new Headers({ foo: 'bar' });\noutgoingMessage.setHeaders(headers);\n```\n\nor\n\n```js\nconst headers = new Map([['foo', 'bar']]);\noutgoingMessage.setHeaders(headers);\n```\n\nWhen headers have been set with [`outgoingMessage.setHeaders()`](#outgoingmessagesetheadersheaders),\nthey will be merged with any headers passed to [`response.writeHead()`](#responsewriteheadstatuscode-statusmessage-headers),\nwith the headers passed to [`response.writeHead()`](#responsewriteheadstatuscode-statusmessage-headers) given precedence.\n\n```js\n// Returns content-type = text/plain\nconst server = http.createServer((req, res) => {\n  const headers = new Headers({ 'Content-Type': 'text/html' });\n  res.setHeaders(headers);\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('ok');\n});\n```","summary":"Sets multiple header values for implicit headers. `headers` must be an instance of `Headers` or `Map`, if a header already exists in the to-be-sent headers, its value will be replaced.","examples":[{"language":"js","displayName":null,"code":"const headers = new Headers({ foo: 'bar' });\noutgoingMessage.setHeaders(headers);"},{"language":"js","displayName":null,"code":"const headers = new Map([['foo', 'bar']]);\noutgoingMessage.setHeaders(headers);"},{"language":"js","displayName":null,"code":"// Returns content-type = text/plain\nconst server = http.createServer((req, res) => {\n  const headers = new Headers({ 'Content-Type': 'text/html' });\n  res.setHeaders(headers);\n  res.writeHead(200, { 'Content-Type': 'text/plain' });\n  res.end('ok');\n});"}],"children":[]},{"kind":"method","id":"outgoingmessagesettimeoutmsecs-callback","name":"setTimeout","title":"`outgoingMessage.setTimeout(msecs[, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.9.12"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"msecs","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Optional function to be called when a timeout\noccurs. Same as binding to the `timeout` event.","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"this","links":[{"name":"this","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Operators/this","start":0,"end":4}]},"description":""}},"description":"Once a socket is associated with the message and is connected,\n[`socket.setTimeout()`](net.html#socketsettimeouttimeout-callback) will be called with `msecs` as the first parameter.","summary":"Once a socket is associated with the message and is connected, `socket.setTimeout()` will be called with `msecs` as the first parameter.","examples":[],"children":[]},{"kind":"property","id":"outgoingmessagesocket","name":"socket","title":"`outgoingMessage.socket`","scope":"module","overloadOf":null,"stability":null,"added":["v0.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"stream.Duplex","links":[{"name":"stream.Duplex","href":"stream.html#class-streamduplex","start":0,"end":13}]},"default":null,"description":"Reference to the underlying socket. Usually, users will not want to access\nthis property.\n\nAfter calling `outgoingMessage.end()`, this property will be nulled.","summary":"Reference to the underlying socket. Usually, users will not want to access this property.","examples":[],"children":[]},{"kind":"method","id":"outgoingmessageuncork","name":"uncork","title":"`outgoingMessage.uncork()`","scope":"module","overloadOf":null,"stability":null,"added":["v13.2.0","v12.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[],"returns":null},"description":"See [`writable.uncork()`](stream.html#writableuncork)","summary":"See `writable.uncork()`","examples":[],"children":[]},{"kind":"property","id":"outgoingmessagewritablecorked","name":"writableCorked","title":"`outgoingMessage.writableCorked`","scope":"module","overloadOf":null,"stability":null,"added":["v13.2.0","v12.16.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"The number of times `outgoingMessage.cork()` has been called.","summary":"The number of times `outgoingMessage.cork()` has been called.","examples":[],"children":[]},{"kind":"property","id":"outgoingmessagewritableended","name":"writableEnded","title":"`outgoingMessage.writableEnded`","scope":"module","overloadOf":null,"stability":null,"added":["v12.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Is `true` if `outgoingMessage.end()` has been called. This property does\nnot indicate whether the data has been flushed. For that purpose, use\n`message.writableFinished` instead.","summary":"Is `true` if `outgoingMessage.end()` has been called. This property does not indicate whether the data has been flushed. For that purpose, use `message.writableFinished` instead.","examples":[],"children":[]},{"kind":"property","id":"outgoingmessagewritablefinished","name":"writableFinished","title":"`outgoingMessage.writableFinished`","scope":"module","overloadOf":null,"stability":null,"added":["v12.7.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Is `true` if all data has been flushed to the underlying system.","summary":"Is `true` if all data has been flushed to the underlying system.","examples":[],"children":[]},{"kind":"property","id":"outgoingmessagewritablehighwatermark","name":"writableHighWaterMark","title":"`outgoingMessage.writableHighWaterMark`","scope":"module","overloadOf":null,"stability":null,"added":["v12.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"The `highWaterMark` of the underlying socket if assigned. Otherwise, the default\nbuffer level when [`writable.write()`](stream.html#writablewritechunk-encoding-callback) starts returning false (`16384`).","summary":"The `highWaterMark` of the underlying socket if assigned. Otherwise, the default buffer level when `writable.write()` starts returning false (`16384`).","examples":[],"children":[]},{"kind":"property","id":"outgoingmessagewritablelength","name":"writableLength","title":"`outgoingMessage.writableLength`","scope":"module","overloadOf":null,"stability":null,"added":["v12.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"The number of buffered bytes.","summary":"The number of buffered bytes.","examples":[],"children":[]},{"kind":"property","id":"outgoingmessagewritableobjectmode","name":"writableObjectMode","title":"`outgoingMessage.writableObjectMode`","scope":"module","overloadOf":null,"stability":null,"added":["v12.9.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"default":null,"description":"Always `false`.","summary":"Always `false`.","examples":[],"children":[]},{"kind":"method","id":"outgoingmessagewritechunk-encoding-callback","name":"write","title":"`outgoingMessage.write(chunk[, encoding][, callback])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.29"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v15.0.0"],"prUrl":"https://github.com/nodejs/node/pull/33155","commit":null,"description":"The `chunk` parameter can now be a `Uint8Array`."},{"versions":["v0.11.6"],"prUrl":null,"commit":null,"description":"The `callback` argument was added."}],"signature":{"parameters":[{"name":"chunk","type":{"text":"string | Buffer | Uint8Array","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"Buffer","href":"buffer.html#class-buffer","start":9,"end":15},{"name":"Uint8Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Uint8Array","start":18,"end":28}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"encoding","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"**Default**: `utf8`","default":null,"optional":true,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":""}},"description":"Sends a chunk of the body. This method can be called multiple times.\n\nThe `encoding` argument is only relevant when `chunk` is a string. Defaults to\n`'utf8'`.\n\nThe `callback` argument is optional and will be called when this chunk of data\nis flushed.\n\nReturns `true` if the entire data was flushed successfully to the kernel\nbuffer. Returns `false` if all or part of the data was queued in the user\nmemory. The `'drain'` event will be emitted when the buffer is free again.","summary":"Sends a chunk of the body. This method can be called multiple times.","examples":[],"children":[]}]},{"kind":"property","id":"httpmethods","name":"METHODS","title":"`http.METHODS`","scope":"module","overloadOf":null,"stability":null,"added":["v0.11.8"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"string[]","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"default":null,"description":"A list of the HTTP methods that are supported by the parser.","summary":"A list of the HTTP methods that are supported by the parser.","examples":[],"children":[]},{"kind":"property","id":"httpstatus_codes","name":"STATUS_CODES","title":"`http.STATUS_CODES`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.22"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"default":null,"description":"A collection of all the standard HTTP response status codes, and the\nshort description of each. For example, `http.STATUS_CODES[404] === 'Not\nFound'`.","summary":"A collection of all the standard HTTP response status codes, and the short description of each. For example, `http.STATUS_CODES[404] === 'NotFound'`.","examples":[],"children":[]},{"kind":"method","id":"httpcreateserveroptions-requestlistener","name":"createServer","title":"`http.createServer([options][, requestListener])`","scope":"module","overloadOf":null,"stability":null,"added":["v0.1.13"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v26.3.0"],"prUrl":"https://github.com/nodejs/node/pull/61597","commit":null,"description":"The `httpValidation` option is supported now."},{"versions":["v25.1.0","v24.12.0"],"prUrl":"https://github.com/nodejs/node/pull/59778","commit":null,"description":"Add optimizeEmptyRequests option."},{"versions":["v24.9.0","v22.21.0"],"prUrl":"https://github.com/nodejs/node/pull/59824","commit":null,"description":"The `shouldUpgradeCallback` option is now supported."},{"versions":["v20.1.0","v18.17.0"],"prUrl":"https://github.com/nodejs/node/pull/47405","commit":null,"description":"The `highWaterMark` option is supported now."},{"versions":["v18.0.0"],"prUrl":"https://github.com/nodejs/node/pull/41263","commit":null,"description":"The `requestTimeout`, `headersTimeout`, `keepAliveTimeout`, and `connectionsCheckingInterval` options are supported now."},{"versions":["v18.0.0"],"prUrl":"https://github.com/nodejs/node/pull/42163","commit":null,"description":"The `noDelay` option now defaults to `true`."},{"versions":["v17.7.0","v16.15.0"],"prUrl":"https://github.com/nodejs/node/pull/41310","commit":null,"description":"The `noDelay`, `keepAlive` and `keepAliveInitialDelay` options are supported now."},{"versions":["v13.8.0","v12.15.0","v10.19.0"],"prUrl":"https://github.com/nodejs/node/pull/31448","commit":null,"description":"The `insecureHTTPParser` option is supported now."},{"versions":["v13.3.0"],"prUrl":"https://github.com/nodejs/node/pull/30570","commit":null,"description":"The `maxHeaderSize` option is supported now."},{"versions":["v9.6.0","v8.12.0"],"prUrl":"https://github.com/nodejs/node/pull/15752","commit":null,"description":"The `options` argument is supported now."}],"signature":{"parameters":[{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"connectionsCheckingInterval","type":null,"description":"Sets the interval value in milliseconds to\ncheck for request and headers timeout in incomplete requests.","default":"30000","optional":true,"rest":false,"properties":[]},{"name":"headersTimeout","type":null,"description":"Sets the timeout value in milliseconds for receiving\nthe complete HTTP headers from the client.\nSee [`server.headersTimeout`](#serverheaderstimeout) for more information.","default":"60000","optional":true,"rest":false,"properties":[]},{"name":"highWaterMark","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Optionally overrides all `socket`s'\n`readableHighWaterMark` and `writableHighWaterMark`. This affects\n`highWaterMark` property of both `IncomingMessage` and `ServerResponse`.","default":"See `stream.getDefaultHighWaterMark()`","optional":true,"rest":false,"properties":[]},{"name":"httpValidation","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Controls HTTP header value validation strictness\nfor incoming requests. Accepted values are:","default":null,"optional":false,"rest":false,"properties":[{"name":"'strict'","type":null,"description":"Strictest validation; rejects any non-ASCII or control\ncharacters in header values.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"'relaxed'","type":null,"description":"Allows a limited set of non-ASCII characters in header\nvalues, aligning with the\n[Fetch specification](https://fetch.spec.whatwg.org/).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"'insecure'","type":null,"description":"Disables all header value validation (equivalent to\n`insecureHTTPParser: true`).\nCannot be used together with `insecureHTTPParser`.","default":"'strict'","optional":true,"rest":false,"properties":[]}]},{"name":"insecureHTTPParser","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If set to `true`, it will use an HTTP parser\nwith leniency flags enabled. Using the insecure parser should be avoided.\nSee [`--insecure-http-parser`](cli.html#--insecure-http-parser) for more information.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"IncomingMessage","type":{"text":"http.IncomingMessage","links":[{"name":"http.IncomingMessage","href":"http.html#class-httpincomingmessage","start":0,"end":20}]},"description":"Specifies the `IncomingMessage`\nclass to be used. Useful for extending the original `IncomingMessage`.","default":"IncomingMessage","optional":true,"rest":false,"properties":[]},{"name":"joinDuplicateHeaders","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If set to `true`, this option allows\njoining the field line values of multiple headers in a request with\na comma (`, `) instead of discarding the duplicates.\nFor more information, refer to [`message.headers`](#messageheaders).","default":"false","optional":true,"rest":false,"properties":[]},{"name":"keepAlive","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If set to `true`, it enables keep-alive functionality\non the socket immediately after a new incoming connection is received,\nsimilarly on what is done in [`socket.setKeepAlive()`](net.html#socketsetkeepalive).","default":"false","optional":true,"rest":false,"properties":[]},{"name":"keepAliveInitialDelay","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"If set to a positive number, it sets the\ninitial delay before the first keepalive probe is sent on an idle socket.","default":"0","optional":true,"rest":false,"properties":[]},{"name":"keepAliveTimeout","type":null,"description":"The number of milliseconds of inactivity a server\nneeds to wait for additional incoming data, after it has finished writing\nthe last response, before a socket will be destroyed.\nSee [`server.keepAliveTimeout`](#serverkeepalivetimeout) for more information.","default":"65000","optional":true,"rest":false,"properties":[]},{"name":"maxHeaderSize","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Optionally overrides the value of\n[`--max-http-header-size`](cli.html#--max-http-header-sizesize) for requests received by this server, i.e.\nthe maximum length of request headers in bytes.","default":"16384 (16 KiB)","optional":true,"rest":false,"properties":[]},{"name":"noDelay","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If set to `true`, it disables the use of Nagle's\nalgorithm immediately after a new incoming connection is received.","default":"true","optional":true,"rest":false,"properties":[]},{"name":"requestTimeout","type":null,"description":"Sets the timeout value in milliseconds for receiving\nthe entire request from the client.\nSee [`server.requestTimeout`](#serverrequesttimeout) for more information.","default":"300000","optional":true,"rest":false,"properties":[]},{"name":"requireHostHeader","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If set to `true`, it forces the server to\nrespond with a 400 (Bad Request) status code to any HTTP/1.1\nrequest message that lacks a Host header\n(as mandated by the specification).","default":"true","optional":true,"rest":false,"properties":[]},{"name":"ServerResponse","type":{"text":"http.ServerResponse","links":[{"name":"http.ServerResponse","href":"http.html#class-httpserverresponse","start":0,"end":19}]},"description":"Specifies the `ServerResponse` class\nto be used. Useful for extending the original `ServerResponse`.","default":"ServerResponse","optional":true,"rest":false,"properties":[]},{"name":"shouldUpgradeCallback(request)","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"A callback which receives an\nincoming request and returns a boolean, to control which upgrade attempts\nshould be accepted. Accepted upgrades will fire an `'upgrade'` event (or\ntheir sockets will be destroyed, if no listener is registered) while\nrejected upgrades will fire a `'request'` event like any non-upgrade\nrequest. This options defaults to\n`() => server.listenerCount('upgrade') > 0`.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"uniqueHeaders","type":{"text":"Array","links":[{"name":"Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array","start":0,"end":5}]},"description":"A list of response headers that should be sent only\nonce. If the header's value is an array, the items will be joined\nusing `; `.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"rejectNonStandardBodyWrites","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If set to `true`, an error is thrown\nwhen writing to an HTTP response which does not have a body.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"optimizeEmptyRequests","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If set to `true`, requests without `Content-Length`\nor `Transfer-Encoding` headers (indicating no body) will be initialized with an\nalready-ended body stream, so they will never emit any stream events\n(like `'data'` or `'end'`). You can use `req.readableEnded` to detect this case.","default":"false","optional":true,"rest":false,"properties":[]}]},{"name":"requestListener","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"http.Server","links":[{"name":"http.Server","href":"http.html#class-httpserver","start":0,"end":11}]},"description":""}},"description":"Returns a new instance of [`http.Server`](#class-httpserver).\n\nThe `requestListener` is a function which is automatically\nadded to the [`'request'`](#event-request) event.\n\n```mjs\nimport http from 'node:http';\n\n// Create a local server to receive data from\nconst server = http.createServer((req, res) => {\n  res.writeHead(200, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({\n    data: 'Hello World!',\n  }));\n});\n\nserver.listen(8000);\n```\n\n```cjs\nconst http = require('node:http');\n\n// Create a local server to receive data from\nconst server = http.createServer((req, res) => {\n  res.writeHead(200, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({\n    data: 'Hello World!',\n  }));\n});\n\nserver.listen(8000);\n```\n\n```mjs\nimport http from 'node:http';\n\n// Create a local server to receive data from\nconst server = http.createServer();\n\n// Listen to the request event\nserver.on('request', (request, res) => {\n  res.writeHead(200, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({\n    data: 'Hello World!',\n  }));\n});\n\nserver.listen(8000);\n```\n\n```cjs\nconst http = require('node:http');\n\n// Create a local server to receive data from\nconst server = http.createServer();\n\n// Listen to the request event\nserver.on('request', (request, res) => {\n  res.writeHead(200, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({\n    data: 'Hello World!',\n  }));\n});\n\nserver.listen(8000);\n```","summary":"Returns a new instance of `http.Server`.","examples":[{"language":"mjs","displayName":null,"code":"import http from 'node:http';\n\n// Create a local server to receive data from\nconst server = http.createServer((req, res) => {\n  res.writeHead(200, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({\n    data: 'Hello World!',\n  }));\n});\n\nserver.listen(8000);"},{"language":"cjs","displayName":null,"code":"const http = require('node:http');\n\n// Create a local server to receive data from\nconst server = http.createServer((req, res) => {\n  res.writeHead(200, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({\n    data: 'Hello World!',\n  }));\n});\n\nserver.listen(8000);"},{"language":"mjs","displayName":null,"code":"import http from 'node:http';\n\n// Create a local server to receive data from\nconst server = http.createServer();\n\n// Listen to the request event\nserver.on('request', (request, res) => {\n  res.writeHead(200, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({\n    data: 'Hello World!',\n  }));\n});\n\nserver.listen(8000);"},{"language":"cjs","displayName":null,"code":"const http = require('node:http');\n\n// Create a local server to receive data from\nconst server = http.createServer();\n\n// Listen to the request event\nserver.on('request', (request, res) => {\n  res.writeHead(200, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({\n    data: 'Hello World!',\n  }));\n});\n\nserver.listen(8000);"}],"children":[]},{"kind":"method","id":"httpgetoptions-callback","name":"get","title":"`http.get(options[, callback])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"options","type":null,"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"callback","type":null,"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"","summary":"","examples":[],"children":[]},{"kind":"method","id":"httpgeturl-options-callback","name":"get","title":"`http.get(url[, options][, callback])`","scope":"module","overloadOf":"httpgetoptions-callback","stability":null,"added":["v0.3.6"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v10.9.0"],"prUrl":"https://github.com/nodejs/node/pull/21616","commit":null,"description":"The `url` parameter can now be passed along with a separate `options` object."},{"versions":["v7.5.0"],"prUrl":"https://github.com/nodejs/node/pull/10638","commit":null,"description":"The `options` parameter can be a WHATWG `URL` object."}],"signature":{"parameters":[{"name":"url","type":{"text":"string | URL","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"URL","href":"url.html#the-whatwg-url-api","start":9,"end":12}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"Accepts the same `options` as\n[`http.request()`](#httprequestoptions-callback), with the method set to GET by default.","default":null,"optional":true,"rest":false,"properties":[]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"http.ClientRequest","links":[{"name":"http.ClientRequest","href":"http.html#class-httpclientrequest","start":0,"end":18}]},"description":""}},"description":"Since most requests are GET requests without bodies, Node.js provides this\nconvenience method. The only difference between this method and\n[`http.request()`](#httprequestoptions-callback) is that it sets the method to GET by default and calls `req.end()`\nautomatically. The callback must take care to consume the response\ndata for reasons stated in [`http.ClientRequest`](#class-httpclientrequest) section.\n\nThe `callback` is invoked with a single argument that is an instance of\n[`http.IncomingMessage`](#class-httpincomingmessage).\n\nJSON fetching example:\n\n```js\nhttp.get('http://localhost:8000/', (res) => {\n  const { statusCode } = res;\n  const contentType = res.headers['content-type'];\n\n  let error;\n  // Any 2xx status code signals a successful response but\n  // here we're only checking for 200.\n  if (statusCode !== 200) {\n    error = new Error('Request Failed.\\n' +\n                      `Status Code: ${statusCode}`);\n  } else if (!/^application\\/json/.test(contentType)) {\n    error = new Error('Invalid content-type.\\n' +\n                      `Expected application/json but received ${contentType}`);\n  }\n  if (error) {\n    console.error(error.message);\n    // Consume response data to free up memory\n    res.resume();\n    return;\n  }\n\n  res.setEncoding('utf8');\n  let rawData = '';\n  res.on('data', (chunk) => { rawData += chunk; });\n  res.on('end', () => {\n    try {\n      const parsedData = JSON.parse(rawData);\n      console.log(parsedData);\n    } catch (e) {\n      console.error(e.message);\n    }\n  });\n}).on('error', (e) => {\n  console.error(`Got error: ${e.message}`);\n});\n\n// Create a local server to receive data from\nconst server = http.createServer((req, res) => {\n  res.writeHead(200, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({\n    data: 'Hello World!',\n  }));\n});\n\nserver.listen(8000);\n```","summary":"Since most requests are GET requests without bodies, Node.js provides this convenience method. The only difference between this method and `http.request()` is that it sets the method to GET by default and calls `req.end()` automatically. The callback must take care to consume the response data for reasons stated in `http.ClientRequest` section.","examples":[{"language":"js","displayName":null,"code":"http.get('http://localhost:8000/', (res) => {\n  const { statusCode } = res;\n  const contentType = res.headers['content-type'];\n\n  let error;\n  // Any 2xx status code signals a successful response but\n  // here we're only checking for 200.\n  if (statusCode !== 200) {\n    error = new Error('Request Failed.\\n' +\n                      `Status Code: ${statusCode}`);\n  } else if (!/^application\\/json/.test(contentType)) {\n    error = new Error('Invalid content-type.\\n' +\n                      `Expected application/json but received ${contentType}`);\n  }\n  if (error) {\n    console.error(error.message);\n    // Consume response data to free up memory\n    res.resume();\n    return;\n  }\n\n  res.setEncoding('utf8');\n  let rawData = '';\n  res.on('data', (chunk) => { rawData += chunk; });\n  res.on('end', () => {\n    try {\n      const parsedData = JSON.parse(rawData);\n      console.log(parsedData);\n    } catch (e) {\n      console.error(e.message);\n    }\n  });\n}).on('error', (e) => {\n  console.error(`Got error: ${e.message}`);\n});\n\n// Create a local server to receive data from\nconst server = http.createServer((req, res) => {\n  res.writeHead(200, { 'Content-Type': 'application/json' });\n  res.end(JSON.stringify({\n    data: 'Hello World!',\n  }));\n});\n\nserver.listen(8000);"}],"children":[]},{"kind":"property","id":"httpglobalagent","name":"globalAgent","title":"`http.globalAgent`","scope":"module","overloadOf":null,"stability":null,"added":["v0.5.9"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v19.0.0"],"prUrl":"https://github.com/nodejs/node/pull/43522","commit":null,"description":"The agent now uses HTTP Keep-Alive and a 5 second timeout by default."}],"type":{"text":"http.Agent","links":[{"name":"http.Agent","href":"http.html#class-httpagent","start":0,"end":10}]},"default":null,"description":"Global instance of `Agent` which is used as the default for all HTTP client\nrequests. Diverges from a default `Agent` configuration by having `keepAlive`\nenabled and a `timeout` of 5 seconds.","summary":"Global instance of `Agent` which is used as the default for all HTTP client requests. Diverges from a default `Agent` configuration by having `keepAlive` enabled and a `timeout` of 5 seconds.","examples":[],"children":[]},{"kind":"property","id":"httpmaxheadersize","name":"maxHeaderSize","title":"`http.maxHeaderSize`","scope":"module","overloadOf":null,"stability":null,"added":["v11.6.0","v10.15.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"default":null,"description":"Read-only property specifying the maximum allowed size of HTTP headers in bytes.\nDefaults to 16 KiB. Configurable using the [`--max-http-header-size`](cli.html#--max-http-header-sizesize) CLI\noption.\n\nThis can be overridden for servers and client requests by passing the\n`maxHeaderSize` option.","summary":"Read-only property specifying the maximum allowed size of HTTP headers in bytes. Defaults to 16 KiB. Configurable using the `--max-http-header-size` CLI option.","examples":[],"children":[]},{"kind":"method","id":"httprequestoptions-callback","name":"request","title":"`http.request(options[, callback])`","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"options","type":null,"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"callback","type":null,"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":null},"description":"","summary":"","examples":[],"children":[]},{"kind":"method","id":"httprequesturl-options-callback","name":"request","title":"`http.request(url[, options][, callback])`","scope":"module","overloadOf":"httprequestoptions-callback","stability":null,"added":["v0.3.6"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v26.3.0"],"prUrl":"https://github.com/nodejs/node/pull/61597","commit":null,"description":"The `httpValidation` option is supported now."},{"versions":["v16.7.0","v14.18.0"],"prUrl":"https://github.com/nodejs/node/pull/39310","commit":null,"description":"When using a `URL` object parsed username and password will now be properly URI decoded."},{"versions":["v15.3.0","v14.17.0"],"prUrl":"https://github.com/nodejs/node/pull/36048","commit":null,"description":"It is possible to abort a request with an AbortSignal."},{"versions":["v13.8.0","v12.15.0","v10.19.0"],"prUrl":"https://github.com/nodejs/node/pull/31448","commit":null,"description":"The `insecureHTTPParser` option is supported now."},{"versions":["v13.3.0"],"prUrl":"https://github.com/nodejs/node/pull/30570","commit":null,"description":"The `maxHeaderSize` option is supported now."},{"versions":["v10.9.0"],"prUrl":"https://github.com/nodejs/node/pull/21616","commit":null,"description":"The `url` parameter can now be passed along with a separate `options` object."},{"versions":["v7.5.0"],"prUrl":"https://github.com/nodejs/node/pull/10638","commit":null,"description":"The `options` parameter can be a WHATWG `URL` object."}],"signature":{"parameters":[{"name":"url","type":{"text":"string | URL","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6},{"name":"URL","href":"url.html#the-whatwg-url-api","start":9,"end":12}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"options","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"","default":null,"optional":true,"rest":false,"properties":[{"name":"agent","type":{"text":"http.Agent | boolean","links":[{"name":"http.Agent","href":"http.html#class-httpagent","start":0,"end":10},{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":13,"end":20}]},"description":"Controls [`Agent`](#class-httpagent) behavior. Possible\nvalues:","default":null,"optional":false,"rest":false,"properties":[{"name":"undefined","type":null,"description":"(default): use [`http.globalAgent`](#httpglobalagent) for this host and port.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"Agent","type":null,"description":"object: explicitly use the passed in `Agent`.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"false","type":null,"description":"causes a new `Agent` with default values to be used.","default":null,"optional":false,"rest":false,"properties":[]}]},{"name":"auth","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Basic authentication (`'user:password'`) to compute an\nAuthorization header.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"createConnection","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"A function that produces a socket/stream to\nuse for the request when the `agent` option is not used. This can be used to\navoid creating a custom `Agent` class just to override the default\n`createConnection` function. See [`agent.createConnection()`](#agentcreateconnectionoptions-callback) for more\ndetails. Any [`Duplex`](stream.html#class-streamduplex) stream is a valid return value.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"defaultPort","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Default port for the protocol.","default":"agent.defaultPort` if an `Agent` is used, else `undefined","optional":true,"rest":false,"properties":[]},{"name":"family","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"IP address family to use when resolving `host` or\n`hostname`. Valid values are `4` or `6`. When unspecified, both IP v4 and\nv6 will be used.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"headers","type":{"text":"Object | Array","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6},{"name":"Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array","start":9,"end":14}]},"description":"An object or an array of strings containing request\nheaders. The array is in the same format as [`message.rawHeaders`](#messagerawheaders).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"hints","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Optional [`dns.lookup()` hints](dns.html#supported-getaddrinfo-flags).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"host","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"A domain name or IP address of the server to issue the\nrequest to.","default":"'localhost'","optional":true,"rest":false,"properties":[]},{"name":"hostname","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Alias for `host`. To support [`url.parse()`](url.html#urlparseurlstring-parsequerystring-slashesdenotehost),\n`hostname` will be used if both `host` and `hostname` are specified.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"httpValidation","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Controls HTTP header value validation strictness\nfor outgoing requests. Accepted values are:","default":null,"optional":false,"rest":false,"properties":[{"name":"'strict'","type":null,"description":"Strictest validation; rejects any non-ASCII or control\ncharacters in header values.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"'relaxed'","type":null,"description":"Allows a limited set of non-ASCII characters in header\nvalues, aligning with the\n[Fetch specification](https://fetch.spec.whatwg.org/).","default":null,"optional":false,"rest":false,"properties":[]},{"name":"'insecure'","type":null,"description":"Disables all header value validation (equivalent to\n`insecureHTTPParser: true`).\nCannot be used together with `insecureHTTPParser`.","default":"'strict'","optional":true,"rest":false,"properties":[]}]},{"name":"insecureHTTPParser","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"If set to `true`, it will use an HTTP parser\nwith leniency flags enabled. Using the insecure parser should be avoided.\nSee [`--insecure-http-parser`](cli.html#--insecure-http-parser) for more information.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"joinDuplicateHeaders","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"It joins the field line values of\nmultiple headers in a request with `, ` instead of discarding\nthe duplicates. See [`message.headers`](#messageheaders) for more information.","default":"false","optional":true,"rest":false,"properties":[]},{"name":"localAddress","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Local interface to bind for network connections.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"localPort","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Local port to connect from.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"lookup","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"Custom lookup function.","default":"dns.lookup()","optional":true,"rest":false,"properties":[]},{"name":"maxHeaderSize","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Optionally overrides the value of\n[`--max-http-header-size`](cli.html#--max-http-header-sizesize) (the maximum length of response headers in\nbytes) for responses received from the server.","default":"16384 (16 KiB)","optional":true,"rest":false,"properties":[]},{"name":"method","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"A string specifying the HTTP request method.","default":"'GET'","optional":true,"rest":false,"properties":[]},{"name":"path","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Request path. Should include query string if any.\nE.G. `'/index.html?page=12'`. An exception is thrown when the request path\ncontains illegal characters. Currently, only spaces are rejected but that\nmay change in the future.","default":"`'/'`. The content in `path` is sent as the request target in the HTTP 1.1 message. When `path` is an absolute URL, this means the request target in the message in absolute form. If the receiving server is a proxy, the server typically forwards the request to the destination specified in the request target, and ignores the `Host` header. The user needs to make sure that `path`, `host` and the Host headers conform to the requirement of the request target in the HTTP specification. When the receiving server is known to be a proxy because the request is routed through Built-in Proxy Support, `http.request` will additionally perform a best-effort check to see that the `host` option or `Host` in `headers` agrees with the authority in `path` during the initial construction of the request. It gives up rewriting the request target for proxying and throws an error if they don't match at request construction time, though there won't be checks for later header mutations done by the user","optional":true,"rest":false,"properties":[]},{"name":"port","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"Port of remote server.","default":"defaultPort` if set, else `80","optional":true,"rest":false,"properties":[]},{"name":"protocol","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Protocol to use.","default":"'http:'","optional":true,"rest":false,"properties":[]},{"name":"setDefaultHeaders","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"Specifies whether or not to automatically add\ndefault headers such as `Connection`, `Content-Length`, `Transfer-Encoding`,\nand `Host`. If set to `false` then all necessary headers must be added\nmanually. Defaults to `true`.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"setHost","type":{"text":"boolean","links":[{"name":"boolean","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#boolean_type","start":0,"end":7}]},"description":"Specifies whether or not to automatically add the\n`Host` header. If provided, this overrides `setDefaultHeaders`. Defaults to\n`true`.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"signal","type":{"text":"AbortSignal","links":[{"name":"AbortSignal","href":"globals.html#class-abortsignal","start":0,"end":11}]},"description":"An AbortSignal that may be used to abort an ongoing\nrequest.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"socketPath","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Unix domain socket. Cannot be used if one of `host`\nor `port` is specified, as those specify a TCP Socket.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"timeout","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"A number specifying the socket timeout in milliseconds.\nThis will set the timeout before the socket is connected.","default":null,"optional":false,"rest":false,"properties":[]},{"name":"uniqueHeaders","type":{"text":"Array","links":[{"name":"Array","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array","start":0,"end":5}]},"description":"A list of request headers that should be sent\nonly once. If the header's value is an array, the items will be joined\nusing `; `.","default":null,"optional":false,"rest":false,"properties":[]}]},{"name":"callback","type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"","default":null,"optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"http.ClientRequest","links":[{"name":"http.ClientRequest","href":"http.html#class-httpclientrequest","start":0,"end":18}]},"description":""}},"description":"`options` in [`socket.connect()`](net.html#socketconnectoptions-connectlistener) are also supported.\n\nNode.js maintains several connections per server to make HTTP requests.\nThis function allows one to transparently issue requests.\n\n`url` can be a string or a [`URL`](url.html#the-whatwg-url-api) object. If `url` is a\nstring, it is automatically parsed with [`new URL()`](url.html#new-urlinput-base). If it is a [`URL`](url.html#the-whatwg-url-api)\nobject, it will be automatically converted to an ordinary `options` object.\n\nIf both `url` and `options` are specified, the objects are merged, with the\n`options` properties taking precedence.\n\nThe optional `callback` parameter will be added as a one-time listener for\nthe [`'response'`](#event-response) event.\n\n`http.request()` returns an instance of the [`http.ClientRequest`](#class-httpclientrequest)\nclass. The `ClientRequest` instance is a writable stream. If one needs to\nupload a file with a POST request, then write to the `ClientRequest` object.\n\n```mjs\nimport http from 'node:http';\nimport { Buffer } from 'node:buffer';\n\nconst postData = JSON.stringify({\n  'msg': 'Hello World!',\n});\n\nconst options = {\n  hostname: 'www.google.com',\n  port: 80,\n  path: '/upload',\n  method: 'POST',\n  headers: {\n    'Content-Type': 'application/json',\n    'Content-Length': Buffer.byteLength(postData),\n  },\n};\n\nconst req = http.request(options, (res) => {\n  console.log(`STATUS: ${res.statusCode}`);\n  console.log(`HEADERS: ${JSON.stringify(res.headers)}`);\n  res.setEncoding('utf8');\n  res.on('data', (chunk) => {\n    console.log(`BODY: ${chunk}`);\n  });\n  res.on('end', () => {\n    console.log('No more data in response.');\n  });\n});\n\nreq.on('error', (e) => {\n  console.error(`problem with request: ${e.message}`);\n});\n\n// Write data to request body\nreq.write(postData);\nreq.end();\n```\n\n```cjs\nconst http = require('node:http');\n\nconst postData = JSON.stringify({\n  'msg': 'Hello World!',\n});\n\nconst options = {\n  hostname: 'www.google.com',\n  port: 80,\n  path: '/upload',\n  method: 'POST',\n  headers: {\n    'Content-Type': 'application/json',\n    'Content-Length': Buffer.byteLength(postData),\n  },\n};\n\nconst req = http.request(options, (res) => {\n  console.log(`STATUS: ${res.statusCode}`);\n  console.log(`HEADERS: ${JSON.stringify(res.headers)}`);\n  res.setEncoding('utf8');\n  res.on('data', (chunk) => {\n    console.log(`BODY: ${chunk}`);\n  });\n  res.on('end', () => {\n    console.log('No more data in response.');\n  });\n});\n\nreq.on('error', (e) => {\n  console.error(`problem with request: ${e.message}`);\n});\n\n// Write data to request body\nreq.write(postData);\nreq.end();\n```\n\nIn the example `req.end()` was called. With `http.request()` one\nmust always call `req.end()` to signify the end of the request -\neven if there is no data being written to the request body.\n\nIf any error is encountered during the request (be that with DNS resolution,\nTCP level errors, or actual HTTP parse errors) an `'error'` event is emitted\non the returned request object. As with all `'error'` events, if no listeners\nare registered the error will be thrown.\n\nThere are a few special headers that should be noted.\n\n* Sending a 'Connection: keep-alive' will notify Node.js that the connection to\n  the server should be persisted until the next request.\n\n* Sending a 'Content-Length' header will disable the default chunked encoding.\n\n* Sending an 'Expect' header will immediately send the request headers.\n  Usually, when sending 'Expect: 100-continue', both a timeout and a listener\n  for the `'continue'` event should be set. See RFC 2616 Section 8.2.3 for more\n  information.\n\n* Sending an Authorization header will override using the `auth` option\n  to compute basic authentication.\n\nExample using a [`URL`](url.html#the-whatwg-url-api) as `options`:\n\n```js\nconst options = new URL('http://abc:xyz@example.com');\n\nconst req = http.request(options, (res) => {\n  // ...\n});\n```\n\nIn a successful request, the following events will be emitted in the following\norder:\n\n* `'socket'`\n* `'response'`\n  * `'data'` any number of times, on the `res` object\n    (`'data'` will not be emitted at all if the response body is empty, for\n    instance, in most redirects)\n  * `'end'` on the `res` object\n* `'close'`\n\nIn the case of a connection error, the following events will be emitted:\n\n* `'socket'`\n* `'error'`\n* `'close'`\n\nIn the case of a premature connection close before the response is received,\nthe following events will be emitted in the following order:\n\n* `'socket'`\n* `'error'` with an error with message `'Error: socket hang up'` and code\n  `'ECONNRESET'`\n* `'close'`\n\nIn the case of a premature connection close after the response is received,\nthe following events will be emitted in the following order:\n\n* `'socket'`\n* `'response'`\n  * `'data'` any number of times, on the `res` object\n* (connection closed here)\n* `'aborted'` on the `res` object\n* `'close'`\n* `'error'` on the `res` object with an error with message\n  `'Error: aborted'` and code `'ECONNRESET'`\n* `'close'` on the `res` object\n\nIf `req.destroy()` is called before a socket is assigned, the following\nevents will be emitted in the following order:\n\n* (`req.destroy()` called here)\n* `'error'` with an error with message `'Error: socket hang up'` and code\n  `'ECONNRESET'`, or the error with which `req.destroy()` was called\n* `'close'`\n\nIf `req.destroy()` is called before the connection succeeds, the following\nevents will be emitted in the following order:\n\n* `'socket'`\n* (`req.destroy()` called here)\n* `'error'` with an error with message `'Error: socket hang up'` and code\n  `'ECONNRESET'`, or the error with which `req.destroy()` was called\n* `'close'`\n\nIf `req.destroy()` is called after the response is received, the following\nevents will be emitted in the following order:\n\n* `'socket'`\n* `'response'`\n  * `'data'` any number of times, on the `res` object\n* (`req.destroy()` called here)\n* `'aborted'` on the `res` object\n* `'close'`\n* `'error'` on the `res` object with an error with message `'Error: aborted'`\n  and code `'ECONNRESET'`, or the error with which `req.destroy()` was called\n* `'close'` on the `res` object\n\nIf `req.abort()` is called before a socket is assigned, the following\nevents will be emitted in the following order:\n\n* (`req.abort()` called here)\n* `'abort'`\n* `'close'`\n\nIf `req.abort()` is called before the connection succeeds, the following\nevents will be emitted in the following order:\n\n* `'socket'`\n* (`req.abort()` called here)\n* `'abort'`\n* `'error'` with an error with message `'Error: socket hang up'` and code\n  `'ECONNRESET'`\n* `'close'`\n\nIf `req.abort()` is called after the response is received, the following\nevents will be emitted in the following order:\n\n* `'socket'`\n* `'response'`\n  * `'data'` any number of times, on the `res` object\n* (`req.abort()` called here)\n* `'abort'`\n* `'aborted'` on the `res` object\n* `'error'` on the `res` object with an error with message\n  `'Error: aborted'` and code `'ECONNRESET'`.\n* `'close'`\n* `'close'` on the `res` object\n\nSetting the `timeout` option or using the `setTimeout()` function will\nnot abort the request or do anything besides add a `'timeout'` event.\n\nPassing an `AbortSignal` and then calling `abort()` on the corresponding\n`AbortController` will behave the same way as calling `.destroy()` on the\nrequest. Specifically, the `'error'` event will be emitted with an error with\nthe message `'AbortError: The operation was aborted'`, the code `'ABORT_ERR'`\nand the `cause`, if one was provided.","summary":"`options` in `socket.connect()` are also supported.","examples":[{"language":"mjs","displayName":null,"code":"import http from 'node:http';\nimport { Buffer } from 'node:buffer';\n\nconst postData = JSON.stringify({\n  'msg': 'Hello World!',\n});\n\nconst options = {\n  hostname: 'www.google.com',\n  port: 80,\n  path: '/upload',\n  method: 'POST',\n  headers: {\n    'Content-Type': 'application/json',\n    'Content-Length': Buffer.byteLength(postData),\n  },\n};\n\nconst req = http.request(options, (res) => {\n  console.log(`STATUS: ${res.statusCode}`);\n  console.log(`HEADERS: ${JSON.stringify(res.headers)}`);\n  res.setEncoding('utf8');\n  res.on('data', (chunk) => {\n    console.log(`BODY: ${chunk}`);\n  });\n  res.on('end', () => {\n    console.log('No more data in response.');\n  });\n});\n\nreq.on('error', (e) => {\n  console.error(`problem with request: ${e.message}`);\n});\n\n// Write data to request body\nreq.write(postData);\nreq.end();"},{"language":"cjs","displayName":null,"code":"const http = require('node:http');\n\nconst postData = JSON.stringify({\n  'msg': 'Hello World!',\n});\n\nconst options = {\n  hostname: 'www.google.com',\n  port: 80,\n  path: '/upload',\n  method: 'POST',\n  headers: {\n    'Content-Type': 'application/json',\n    'Content-Length': Buffer.byteLength(postData),\n  },\n};\n\nconst req = http.request(options, (res) => {\n  console.log(`STATUS: ${res.statusCode}`);\n  console.log(`HEADERS: ${JSON.stringify(res.headers)}`);\n  res.setEncoding('utf8');\n  res.on('data', (chunk) => {\n    console.log(`BODY: ${chunk}`);\n  });\n  res.on('end', () => {\n    console.log('No more data in response.');\n  });\n});\n\nreq.on('error', (e) => {\n  console.error(`problem with request: ${e.message}`);\n});\n\n// Write data to request body\nreq.write(postData);\nreq.end();"},{"language":"js","displayName":null,"code":"const options = new URL('http://abc:xyz@example.com');\n\nconst req = http.request(options, (res) => {\n  // ...\n});"}],"children":[]},{"kind":"method","id":"httpvalidateheadernamename-label","name":"validateHeaderName","title":"`http.validateHeaderName(name[, label])`","scope":"module","overloadOf":null,"stability":null,"added":["v14.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[{"versions":["v19.5.0","v18.14.0"],"prUrl":"https://github.com/nodejs/node/pull/46143","commit":null,"description":"The `label` parameter is added."}],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"label","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"Label for error message.","default":"'Header name'","optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Performs the low-level validations on the provided `name` that are done when\n`res.setHeader(name, value)` is called.\n\nPassing illegal value as `name` will result in a [`TypeError`](errors.html#class-typeerror) being thrown,\nidentified by `code: 'ERR_INVALID_HTTP_TOKEN'`.\n\nIt is not necessary to use this method before passing headers to an HTTP request\nor response. The HTTP module will automatically validate such headers.\n\nExample:\n\n```mjs\nimport { validateHeaderName } from 'node:http';\n\ntry {\n  validateHeaderName('');\n} catch (err) {\n  console.error(err instanceof TypeError); // --> true\n  console.error(err.code); // --> 'ERR_INVALID_HTTP_TOKEN'\n  console.error(err.message); // --> 'Header name must be a valid HTTP token [\"\"]'\n}\n```\n\n```cjs\nconst { validateHeaderName } = require('node:http');\n\ntry {\n  validateHeaderName('');\n} catch (err) {\n  console.error(err instanceof TypeError); // --> true\n  console.error(err.code); // --> 'ERR_INVALID_HTTP_TOKEN'\n  console.error(err.message); // --> 'Header name must be a valid HTTP token [\"\"]'\n}\n```","summary":"Performs the low-level validations on the provided `name` that are done when `res.setHeader(name, value)` is called.","examples":[{"language":"mjs","displayName":null,"code":"import { validateHeaderName } from 'node:http';\n\ntry {\n  validateHeaderName('');\n} catch (err) {\n  console.error(err instanceof TypeError); // --> true\n  console.error(err.code); // --> 'ERR_INVALID_HTTP_TOKEN'\n  console.error(err.message); // --> 'Header name must be a valid HTTP token [\"\"]'\n}"},{"language":"cjs","displayName":null,"code":"const { validateHeaderName } = require('node:http');\n\ntry {\n  validateHeaderName('');\n} catch (err) {\n  console.error(err instanceof TypeError); // --> true\n  console.error(err.code); // --> 'ERR_INVALID_HTTP_TOKEN'\n  console.error(err.message); // --> 'Header name must be a valid HTTP token [\"\"]'\n}"}],"children":[]},{"kind":"method","id":"httpvalidateheadervaluename-value","name":"validateHeaderValue","title":"`http.validateHeaderValue(name, value)`","scope":"module","overloadOf":null,"stability":null,"added":["v14.3.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"name","type":{"text":"string","links":[{"name":"string","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#string_type","start":0,"end":6}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]},{"name":"value","type":{"text":"any","links":[{"name":"any","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#Data_types","start":0,"end":3}]},"description":"","default":null,"optional":false,"rest":false,"properties":[]}],"returns":null},"description":"Performs the low-level validations on the provided `value` that are done when\n`res.setHeader(name, value)` is called.\n\nPassing illegal value as `value` will result in a [`TypeError`](errors.html#class-typeerror) being thrown.\n\n* Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`.\n* Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`.\n\nIt is not necessary to use this method before passing headers to an HTTP request\nor response. The HTTP module will automatically validate such headers.\n\nExamples:\n\n```mjs\nimport { validateHeaderValue } from 'node:http';\n\ntry {\n  validateHeaderValue('x-my-header', undefined);\n} catch (err) {\n  console.error(err instanceof TypeError); // --> true\n  console.error(err.code === 'ERR_HTTP_INVALID_HEADER_VALUE'); // --> true\n  console.error(err.message); // --> 'Invalid value \"undefined\" for header \"x-my-header\"'\n}\n\ntry {\n  validateHeaderValue('x-my-header', 'oʊmɪɡə');\n} catch (err) {\n  console.error(err instanceof TypeError); // --> true\n  console.error(err.code === 'ERR_INVALID_CHAR'); // --> true\n  console.error(err.message); // --> 'Invalid character in header content [\"x-my-header\"]'\n}\n```\n\n```cjs\nconst { validateHeaderValue } = require('node:http');\n\ntry {\n  validateHeaderValue('x-my-header', undefined);\n} catch (err) {\n  console.error(err instanceof TypeError); // --> true\n  console.error(err.code === 'ERR_HTTP_INVALID_HEADER_VALUE'); // --> true\n  console.error(err.message); // --> 'Invalid value \"undefined\" for header \"x-my-header\"'\n}\n\ntry {\n  validateHeaderValue('x-my-header', 'oʊmɪɡə');\n} catch (err) {\n  console.error(err instanceof TypeError); // --> true\n  console.error(err.code === 'ERR_INVALID_CHAR'); // --> true\n  console.error(err.message); // --> 'Invalid character in header content [\"x-my-header\"]'\n}\n```","summary":"Performs the low-level validations on the provided `value` that are done when `res.setHeader(name, value)` is called.","examples":[{"language":"mjs","displayName":null,"code":"import { validateHeaderValue } from 'node:http';\n\ntry {\n  validateHeaderValue('x-my-header', undefined);\n} catch (err) {\n  console.error(err instanceof TypeError); // --> true\n  console.error(err.code === 'ERR_HTTP_INVALID_HEADER_VALUE'); // --> true\n  console.error(err.message); // --> 'Invalid value \"undefined\" for header \"x-my-header\"'\n}\n\ntry {\n  validateHeaderValue('x-my-header', 'oʊmɪɡə');\n} catch (err) {\n  console.error(err instanceof TypeError); // --> true\n  console.error(err.code === 'ERR_INVALID_CHAR'); // --> true\n  console.error(err.message); // --> 'Invalid character in header content [\"x-my-header\"]'\n}"},{"language":"cjs","displayName":null,"code":"const { validateHeaderValue } = require('node:http');\n\ntry {\n  validateHeaderValue('x-my-header', undefined);\n} catch (err) {\n  console.error(err instanceof TypeError); // --> true\n  console.error(err.code === 'ERR_HTTP_INVALID_HEADER_VALUE'); // --> true\n  console.error(err.message); // --> 'Invalid value \"undefined\" for header \"x-my-header\"'\n}\n\ntry {\n  validateHeaderValue('x-my-header', 'oʊmɪɡə');\n} catch (err) {\n  console.error(err instanceof TypeError); // --> true\n  console.error(err.code === 'ERR_INVALID_CHAR'); // --> true\n  console.error(err.message); // --> 'Invalid character in header content [\"x-my-header\"]'\n}"}],"children":[]},{"kind":"method","id":"httpsetmaxidlehttpparsersmax","name":"setMaxIdleHTTPParsers","title":"`http.setMaxIdleHTTPParsers(max)`","scope":"module","overloadOf":null,"stability":null,"added":["v18.8.0","v16.18.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"max","type":{"text":"number","links":[{"name":"number","href":"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Data_structures#number_type","start":0,"end":6}]},"description":"","default":"1000","optional":true,"rest":false,"properties":[]}],"returns":null},"description":"Set the maximum number of idle HTTP parsers.","summary":"Set the maximum number of idle HTTP parsers.","examples":[],"children":[]},{"kind":"method","id":"httpsetglobalproxyfromenvproxyenv","name":"setGlobalProxyFromEnv","title":"`http.setGlobalProxyFromEnv([proxyEnv])`","scope":"module","overloadOf":null,"stability":null,"added":["v25.4.0","v24.14.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"signature":{"parameters":[{"name":"proxyEnv","type":{"text":"Object","links":[{"name":"Object","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Object","start":0,"end":6}]},"description":"An object containing proxy configuration. This accepts the\nsame options as the `proxyEnv` option accepted by [`Agent`](#class-httpagent).","default":"process.env","optional":true,"rest":false,"properties":[]}],"returns":{"type":{"text":"Function","links":[{"name":"Function","href":"https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Function","start":0,"end":8}]},"description":"A function that restores the original agent and dispatcher\nsettings to the state before this `http.setGlobalProxyFromEnv()` is invoked."}},"description":"Dynamically resets the global configurations to enable built-in proxy support for\n`fetch()` and `http.request()`/`https.request()` at runtime, as an alternative\nto using the `--use-env-proxy` flag or `NODE_USE_ENV_PROXY` environment variable.\nIt can also be used to override settings configured from the environment variables.\n\nAs this function resets the global configurations, any previously configured\n`http.globalAgent`, `https.globalAgent` or undici global dispatcher would be\noverridden after this function is invoked. It's recommended to invoke it before any\nrequests are made and avoid invoking it in the middle of any requests.\n\nSee [Built-in Proxy Support](#built-in-proxy-support) for details on proxy URL formats and `NO_PROXY`\nsyntax.","summary":"Dynamically resets the global configurations to enable built-in proxy support for `fetch()` and `http.request()`/`https.request()` at runtime, as an alternative to using the `--use-env-proxy` flag or `NODE_USE_ENV_PROXY` environment variable. It can also be used to override settings configured from the environment variables.","examples":[],"children":[]},{"kind":"class","id":"class-websocket","name":"WebSocket","title":"Class: `WebSocket`","scope":"module","overloadOf":null,"stability":null,"added":["v22.5.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"extends":null,"description":"A browser-compatible implementation of {WebSocket}.","summary":"A browser-compatible implementation of {WebSocket}.","examples":[],"children":[]},{"kind":"section","id":"built-in-proxy-support","name":"Built-in Proxy Support","title":"Built-in Proxy Support","scope":"module","overloadOf":null,"stability":{"index":"1.1","description":"Active development"},"added":["v24.5.0","v22.21.0"],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"When Node.js creates the global agent, if the `NODE_USE_ENV_PROXY` environment variable is\nset to `1` or `--use-env-proxy` is enabled, the global agent will be constructed\nwith `proxyEnv: process.env`, enabling proxy support based on the environment variables.\n\nTo enable proxy support dynamically and globally, use [`http.setGlobalProxyFromEnv()`](#httpsetglobalproxyfromenvproxyenv).\n\nCustom agents can also be created with proxy support by passing a\n`proxyEnv` option when constructing the agent. The value can be `process.env`\nif they just want to inherit the configuration from the environment variables,\nor an object with specific setting overriding the environment.\n\nThe following properties of the `proxyEnv` are checked to configure proxy\nsupport.\n\n* `HTTP_PROXY` or `http_proxy`: Proxy server URL for HTTP requests. If both are set,\n  `http_proxy` takes precedence.\n* `HTTPS_PROXY` or `https_proxy`: Proxy server URL for HTTPS requests. If both are set,\n  `https_proxy` takes precedence.\n* `NO_PROXY` or `no_proxy`: Comma-separated list of hosts to bypass the proxy. If both are set,\n  `no_proxy` takes precedence.\n\nIf the request is made to a Unix domain socket, the proxy settings will be ignored.","summary":"When Node.js creates the global agent, if the `NODE_USE_ENV_PROXY` environment variable is set to `1` or `--use-env-proxy` is enabled, the global agent will be constructed with `proxyEnv: process.env`, enabling proxy support based on the environment variables.","examples":[],"children":[{"kind":"section","id":"proxy-security-considerations","name":"Proxy security considerations","title":"Proxy security considerations","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Built-in proxy support routes outbound requests through an HTTP(S) proxy, often\nbecause a firewall requires one to access external networks. It is not an\nanonymity or traffic-hiding feature and does not attempt to hide traffic from\nthe proxy, the local network, network operators, or authorities that govern the\ndeployment.\n\nConfigure only proxies that are trusted and authorized for the deployment. A\nproxy can observe connection metadata; for plain HTTP requests, or when TLS is\nterminated or intercepted by the proxy, it can also observe request and response\ncontents. Node.js does not support treating an untrusted proxy as a privacy\nboundary. Deployment operators are responsible for controlling proxy\nconfiguration and for meeting deployment-specific network policy and legal\nrequirements.","summary":"Built-in proxy support routes outbound requests through an HTTP(S) proxy, often because a firewall requires one to access external networks. It is not an anonymity or traffic-hiding feature and does not attempt to hide traffic from the proxy, the local network, network operators, or authorities that govern the deployment.","examples":[],"children":[]},{"kind":"section","id":"proxy-url-format","name":"Proxy URL Format","title":"Proxy URL Format","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"Proxy URLs can use either HTTP or HTTPS protocols:\n\n* HTTP proxy: `http://proxy.example.com:8080`\n* HTTPS proxy: `https://proxy.example.com:8080`\n* Proxy with authentication: `http://username:password@proxy.example.com:8080`","summary":"Proxy URLs can use either HTTP or HTTPS protocols:","examples":[],"children":[]},{"kind":"section","id":"no_proxy-format","name":"NO_PROXY Format","title":"`NO_PROXY` Format","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"The `NO_PROXY` environment variable supports several formats:\n\n* `*` - Bypass proxy for all hosts\n* `example.com` - Exact host name match\n* `.example.com` - Domain suffix match (matches `sub.example.com`)\n* `*.example.com` - Wildcard domain match\n* `192.168.1.100` - Exact IP address match\n* `192.168.1.1-192.168.1.100` - IP address range\n* `example.com:8080` - Hostname with specific port\n\nMultiple entries should be separated by commas.","summary":"The `NO_PROXY` environment variable supports several formats:","examples":[],"children":[]},{"kind":"section","id":"example","name":"Example","title":"Example","scope":"module","overloadOf":null,"stability":null,"added":[],"deprecated":[],"removed":[],"napiVersion":[],"changes":[],"description":"To start a Node.js process with proxy support enabled for all requests sent\nthrough the default global agent, either use the `NODE_USE_ENV_PROXY` environment\nvariable:\n\n```console\nNODE_USE_ENV_PROXY=1 HTTP_PROXY=http://proxy.example.com:8080 NO_PROXY=localhost,127.0.0.1 node client.js\n```\n\nOr the `--use-env-proxy` flag.\n\n```console\nHTTP_PROXY=http://proxy.example.com:8080 NO_PROXY=localhost,127.0.0.1 node --use-env-proxy client.js\n```\n\nTo enable proxy support dynamically and globally with `process.env` (the default option of `http.setGlobalProxyFromEnv()`):\n\n```cjs\nconst http = require('node:http');\n\n// Reads proxy-related environment variables from process.env\nconst restore = http.setGlobalProxyFromEnv();\n\n// Subsequent requests will use the configured proxies from environment variables\nhttp.get('http://www.example.com', (res) => {\n  // This request will be proxied if HTTP_PROXY or http_proxy is set\n});\n\nfetch('https://www.example.com', (res) => {\n  // This request will be proxied if HTTPS_PROXY or https_proxy is set\n});\n\n// To restore the original global agent and dispatcher settings, call the returned function.\n// restore();\n```\n\n```mjs\nimport http from 'node:http';\n\n// Reads proxy-related environment variables from process.env\nhttp.setGlobalProxyFromEnv();\n\n// Subsequent requests will use the configured proxies from environment variables\nhttp.get('http://www.example.com', (res) => {\n  // This request will be proxied if HTTP_PROXY or http_proxy is set\n});\n\nfetch('https://www.example.com', (res) => {\n  // This request will be proxied if HTTPS_PROXY or https_proxy is set\n});\n\n// To restore the original global agent and dispatcher settings, call the returned function.\n// restore();\n```\n\nTo enable proxy support dynamically and globally with custom settings:\n\n```cjs\nconst http = require('node:http');\n\nconst restore = http.setGlobalProxyFromEnv({\n  http_proxy: 'http://proxy.example.com:8080',\n  https_proxy: 'https://proxy.example.com:8443',\n  no_proxy: 'localhost,127.0.0.1,.internal.example.com',\n});\n\n// Subsequent requests will use the configured proxies\nhttp.get('http://www.example.com', (res) => {\n  // This request will be proxied through proxy.example.com:8080\n});\n\nfetch('https://www.example.com', (res) => {\n  // This request will be proxied through proxy.example.com:8443\n});\n```\n\n```mjs\nimport http from 'node:http';\n\nhttp.setGlobalProxyFromEnv({\n  http_proxy: 'http://proxy.example.com:8080',\n  https_proxy: 'https://proxy.example.com:8443',\n  no_proxy: 'localhost,127.0.0.1,.internal.example.com',\n});\n\n// Subsequent requests will use the configured proxies\nhttp.get('http://www.example.com', (res) => {\n  // This request will be proxied through proxy.example.com:8080\n});\n\nfetch('https://www.example.com', (res) => {\n  // This request will be proxied through proxy.example.com:8443\n});\n```\n\nTo create a custom agent with built-in proxy support:\n\n```cjs\nconst http = require('node:http');\n\n// Creating a custom agent with custom proxy support.\nconst agent = new http.Agent({ proxyEnv: { HTTP_PROXY: 'http://proxy.example.com:8080' } });\n\nhttp.request({\n  hostname: 'www.example.com',\n  port: 80,\n  path: '/',\n  agent,\n}, (res) => {\n  // This request will be proxied through proxy.example.com:8080 using the HTTP protocol.\n  console.log(`STATUS: ${res.statusCode}`);\n});\n```\n\nAlternatively, the following also works:\n\n```cjs\nconst http = require('node:http');\n// Use lower-cased option name.\nconst agent1 = new http.Agent({ proxyEnv: { http_proxy: 'http://proxy.example.com:8080' } });\n// Use values inherited from the environment variables, if the process is started with\n// HTTP_PROXY=http://proxy.example.com:8080 this will use the proxy server specified\n// in process.env.HTTP_PROXY.\nconst agent2 = new http.Agent({ proxyEnv: process.env });\n```","summary":"To start a Node.js process with proxy support enabled for all requests sent through the default global agent, either use the `NODE_USE_ENV_PROXY` environment variable:","examples":[{"language":"console","displayName":null,"code":"NODE_USE_ENV_PROXY=1 HTTP_PROXY=http://proxy.example.com:8080 NO_PROXY=localhost,127.0.0.1 node client.js"},{"language":"console","displayName":null,"code":"HTTP_PROXY=http://proxy.example.com:8080 NO_PROXY=localhost,127.0.0.1 node --use-env-proxy client.js"},{"language":"cjs","displayName":null,"code":"const http = require('node:http');\n\n// Reads proxy-related environment variables from process.env\nconst restore = http.setGlobalProxyFromEnv();\n\n// Subsequent requests will use the configured proxies from environment variables\nhttp.get('http://www.example.com', (res) => {\n  // This request will be proxied if HTTP_PROXY or http_proxy is set\n});\n\nfetch('https://www.example.com', (res) => {\n  // This request will be proxied if HTTPS_PROXY or https_proxy is set\n});\n\n// To restore the original global agent and dispatcher settings, call the returned function.\n// restore();"},{"language":"mjs","displayName":null,"code":"import http from 'node:http';\n\n// Reads proxy-related environment variables from process.env\nhttp.setGlobalProxyFromEnv();\n\n// Subsequent requests will use the configured proxies from environment variables\nhttp.get('http://www.example.com', (res) => {\n  // This request will be proxied if HTTP_PROXY or http_proxy is set\n});\n\nfetch('https://www.example.com', (res) => {\n  // This request will be proxied if HTTPS_PROXY or https_proxy is set\n});\n\n// To restore the original global agent and dispatcher settings, call the returned function.\n// restore();"},{"language":"cjs","displayName":null,"code":"const http = require('node:http');\n\nconst restore = http.setGlobalProxyFromEnv({\n  http_proxy: 'http://proxy.example.com:8080',\n  https_proxy: 'https://proxy.example.com:8443',\n  no_proxy: 'localhost,127.0.0.1,.internal.example.com',\n});\n\n// Subsequent requests will use the configured proxies\nhttp.get('http://www.example.com', (res) => {\n  // This request will be proxied through proxy.example.com:8080\n});\n\nfetch('https://www.example.com', (res) => {\n  // This request will be proxied through proxy.example.com:8443\n});"},{"language":"mjs","displayName":null,"code":"import http from 'node:http';\n\nhttp.setGlobalProxyFromEnv({\n  http_proxy: 'http://proxy.example.com:8080',\n  https_proxy: 'https://proxy.example.com:8443',\n  no_proxy: 'localhost,127.0.0.1,.internal.example.com',\n});\n\n// Subsequent requests will use the configured proxies\nhttp.get('http://www.example.com', (res) => {\n  // This request will be proxied through proxy.example.com:8080\n});\n\nfetch('https://www.example.com', (res) => {\n  // This request will be proxied through proxy.example.com:8443\n});"},{"language":"cjs","displayName":null,"code":"const http = require('node:http');\n\n// Creating a custom agent with custom proxy support.\nconst agent = new http.Agent({ proxyEnv: { HTTP_PROXY: 'http://proxy.example.com:8080' } });\n\nhttp.request({\n  hostname: 'www.example.com',\n  port: 80,\n  path: '/',\n  agent,\n}, (res) => {\n  // This request will be proxied through proxy.example.com:8080 using the HTTP protocol.\n  console.log(`STATUS: ${res.statusCode}`);\n});"},{"language":"cjs","displayName":null,"code":"const http = require('node:http');\n// Use lower-cased option name.\nconst agent1 = new http.Agent({ proxyEnv: { http_proxy: 'http://proxy.example.com:8080' } });\n// Use values inherited from the environment variables, if the process is started with\n// HTTP_PROXY=http://proxy.example.com:8080 this will use the proxy server specified\n// in process.env.HTTP_PROXY.\nconst agent2 = new http.Agent({ proxyEnv: process.env });"}],"children":[]}]}]}