diff options
author | Rich Trott <rtrott@gmail.com> | 2021-10-11 07:55:04 +0300 |
---|---|---|
committer | Antoine du Hamel <duhamelantoine1995@gmail.com> | 2021-10-20 12:59:11 +0300 |
commit | d0b58c0287e67a139137aa906819d95f8314b093 (patch) | |
tree | e9a92870138d89b608b1c6e6568611744c32c4f2 /doc/api/http.md | |
parent | a7c17e08de658cbc0beefd8e9583803b5a62ac7e (diff) |
doc: format doc/api/*.md with markdown formatter
PR-URL: https://github.com/nodejs/node/pull/40403
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
Reviewed-By: Michaƫl Zasso <targos@protonmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Diffstat (limited to 'doc/api/http.md')
-rw-r--r-- | doc/api/http.md | 196 |
1 files changed, 176 insertions, 20 deletions
diff --git a/doc/api/http.md b/doc/api/http.md index 09aa425b0f9..722defc987d 100644 --- a/doc/api/http.md +++ b/doc/api/http.md @@ -17,6 +17,7 @@ user is able to stream data. HTTP message headers are represented by an object like this: <!-- eslint-skip --> + ```js { 'content-length': '123', 'content-type': 'text/plain', @@ -40,6 +41,7 @@ example, the previous message header object might have a `rawHeaders` list like the following: <!-- eslint-disable semi --> + ```js [ 'ConTent-Length', '123456', 'content-LENGTH', '123', @@ -50,6 +52,7 @@ list like the following: ``` ## Class: `http.Agent` + <!-- YAML added: v0.3.4 --> @@ -110,6 +113,7 @@ http.get({ ``` ### `new Agent([options])` + <!-- YAML added: v0.3.4 changes: @@ -146,13 +150,13 @@ changes: for TCP Keep-Alive packets. Ignored when the `keepAlive` option is `false` or `undefined`. **Default:** `1000`. * `maxSockets` {number} Maximum number of sockets to allow per host. - If the same host opens multiple concurrent connections, each request - will use new socket until the `maxSockets` value is reached. - If the host attempts to open more connections than `maxSockets`, - the additional requests will enter into a pending request queue, and - will enter active connection state when an existing connection terminates. - This makes sure there are at most `maxSockets` active connections at - any point in time, from a given host. + If the same host opens multiple concurrent connections, each request + will use new socket until the `maxSockets` value is reached. + If the host attempts to open more connections than `maxSockets`, + the additional requests will enter into a pending request queue, and + will enter active connection state when an existing connection terminates. + This makes sure there are at most `maxSockets` active connections at + any point in time, from a given host. **Default:** `Infinity`. * `maxTotalSockets` {number} Maximum number of sockets allowed for all hosts in total. Each request will use a new socket @@ -191,6 +195,7 @@ http.request(options, onResponseCallback); ``` ### `agent.createConnection(options[, callback])` + <!-- YAML added: v0.11.4 --> @@ -215,6 +220,7 @@ type other than {net.Socket}. `callback` has a signature of `(err, stream)`. ### `agent.keepSocketAlive(socket)` + <!-- YAML added: v8.1.0 --> @@ -238,6 +244,7 @@ The `socket` argument can be an instance of {net.Socket}, a subclass of {stream.Duplex}. ### `agent.reuseSocket(socket, request)` + <!-- YAML added: v8.1.0 --> @@ -258,6 +265,7 @@ The `socket` argument can be an instance of {net.Socket}, a subclass of {stream.Duplex}. ### `agent.destroy()` + <!-- YAML added: v0.11.4 --> @@ -271,6 +279,7 @@ sockets might stay open for quite a long time before the server terminates them. ### `agent.freeSockets` + <!-- YAML added: v0.11.4 changes: @@ -288,6 +297,7 @@ Sockets in the `freeSockets` list will be automatically destroyed and removed from the array on `'timeout'`. ### `agent.getName(options)` + <!-- YAML added: v0.11.4 --> @@ -308,6 +318,7 @@ the name includes the CA, cert, ciphers, and other HTTPS/TLS-specific options that determine socket reusability. ### `agent.maxFreeSockets` + <!-- YAML added: v0.11.7 --> @@ -319,6 +330,7 @@ sets the maximum number of sockets that will be left open in the free state. ### `agent.maxSockets` + <!-- YAML added: v0.3.6 --> @@ -329,6 +341,7 @@ 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()`][]. ### `agent.maxTotalSockets` + <!-- YAML added: - v14.5.0 @@ -341,6 +354,7 @@ By default set to `Infinity`. Determines how many concurrent sockets the agent can have open. Unlike `maxSockets`, this parameter applies across all origins. ### `agent.requests` + <!-- YAML added: v0.5.9 changes: @@ -355,6 +369,7 @@ An object which contains queues of requests that have not yet been assigned to sockets. Do not modify. ### `agent.sockets` + <!-- YAML added: v0.3.6 changes: @@ -369,6 +384,7 @@ An object which contains arrays of sockets currently in use by the agent. Do not modify. ## Class: `http.ClientRequest` + <!-- YAML added: v0.1.17 --> @@ -378,7 +394,7 @@ added: v0.1.17 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 +[`getHeader(name)`][], [`removeHeader(name)`][] API. The actual header will be sent along with the first data chunk or when calling [`request.end()`][]. To get the response, add a listener for [`'response'`][] to the request object. @@ -405,6 +421,7 @@ Node.js does not check whether Content-Length and the length of the body which has been transmitted are equal or not. ### Event: `'abort'` + <!-- YAML added: v1.4.1 deprecated: v17.0.0 @@ -416,6 +433,7 @@ Emitted when the request has been aborted by the client. This event is only emitted on the first call to `abort()`. ### Event: `'connect'` + <!-- YAML added: v0.7.0 --> @@ -490,6 +508,7 @@ proxy.listen(1337, '127.0.0.1', () => { ``` ### Event: `'continue'` + <!-- YAML added: v0.3.2 --> @@ -499,6 +518,7 @@ the request contained 'Expect: 100-continue'. This is an instruction that the client should send the request body. ### Event: `'information'` + <!-- YAML added: v10.0.0 --> @@ -510,7 +530,7 @@ added: v10.0.0 * `statusCode` {integer} * `statusMessage` {string} * `headers` {Object} - * `rawHeaders` {string[]} + * `rawHeaders` {string\[]} Emitted when the server sends a 1xx intermediate response (excluding 101 Upgrade). The listeners of this event will receive an object containing the @@ -541,6 +561,7 @@ upgrades, or HTTP 2.0. To be notified of 101 Upgrade notices, listen for the [`'upgrade'`][] event instead. ### Event: `'response'` + <!-- YAML added: v0.1.0 --> @@ -551,6 +572,7 @@ Emitted when a response is received to this request. This event is emitted only once. ### Event: `'socket'` + <!-- YAML added: v0.5.3 --> @@ -562,6 +584,7 @@ a subclass of {stream.Duplex}, unless the user specifies a socket type other than {net.Socket}. ### Event: `'timeout'` + <!-- YAML added: v0.7.8 --> @@ -572,6 +595,7 @@ that the socket has been idle. The request must be destroyed manually. See also: [`request.setTimeout()`][]. ### Event: `'upgrade'` + <!-- YAML added: v0.1.94 --> @@ -633,6 +657,7 @@ server.listen(1337, '127.0.0.1', () => { ``` ### `request.abort()` + <!-- YAML added: v0.3.8 deprecated: @@ -646,6 +671,7 @@ Marks the request as aborting. Calling this will cause remaining data in the response to be dropped and the socket to be destroyed. ### `request.aborted` + <!-- YAML added: v0.11.14 deprecated: v17.0.0 @@ -663,6 +689,7 @@ The `request.aborted` property will be `true` if the request has been aborted. ### `request.connection` + <!-- YAML added: v0.3.0 deprecated: v13.0.0 @@ -675,6 +702,7 @@ deprecated: v13.0.0 See [`request.socket`][]. ### `request.end([data[, encoding]][, callback])` + <!-- YAML added: v0.1.90 changes: @@ -699,6 +727,7 @@ If `callback` is specified, it will be called when the request stream is finished. ### `request.destroy([error])` + <!-- YAML added: v0.3.0 changes: @@ -718,6 +747,7 @@ in the response to be dropped and the socket to be destroyed. See [`writable.destroy()`][] for further details. #### `request.destroyed` + <!-- YAML added: - v14.1.0 @@ -731,6 +761,7 @@ Is `true` after [`request.destroy()`][] has been called. See [`writable.destroyed`][] for further details. ### `request.finished` + <!-- YAML added: v0.0.1 deprecated: @@ -747,6 +778,7 @@ has been called. `request.end()` will automatically be called if the request was initiated via [`http.get()`][]. ### `request.flushHeaders()` + <!-- YAML added: v1.6.0 --> @@ -762,6 +794,7 @@ data is not sent until possibly much later. `request.flushHeaders()` bypasses the optimization and kickstarts the request. ### `request.getHeader(name)` + <!-- YAML added: v1.6.0 --> @@ -786,13 +819,14 @@ const cookie = request.getHeader('Cookie'); ``` ### `request.getRawHeaderNames()` + <!-- YAML added: - v15.13.0 - v14.17.0 --> -* Returns: {string[]} +* Returns: {string\[]} Returns an array containing the unique names of the current outgoing raw headers. Header names are returned with their exact casing being set. @@ -812,6 +846,7 @@ const headerNames = request.getRawHeaderNames(); Limits maximum response headers count. If set to 0, no limit will be applied. ### `request.path` + <!-- YAML added: v0.4.0 --> @@ -819,6 +854,7 @@ added: v0.4.0 * {string} The request path. ### `request.method` + <!-- YAML added: v0.1.97 --> @@ -826,6 +862,7 @@ added: v0.1.97 * {string} The request method. ### `request.host` + <!-- YAML added: - v14.5.0 @@ -835,6 +872,7 @@ added: * {string} The request host. ### `request.protocol` + <!-- YAML added: - v14.5.0 @@ -844,6 +882,7 @@ added: * {string} The request protocol. ### `request.removeHeader(name)` + <!-- YAML added: v1.6.0 --> @@ -857,6 +896,7 @@ request.removeHeader('Content-Type'); ``` ### `request.reusedSocket` + <!-- YAML added: - v13.0.0 @@ -914,6 +954,7 @@ retriableRequest(); ``` ### `request.setHeader(name, value)` + <!-- YAML added: v1.6.0 --> @@ -939,6 +980,7 @@ request.setHeader('Cookie', ['type=ninja', 'language=javascript']); ``` ### `request.setNoDelay([noDelay])` + <!-- YAML added: v0.5.9 --> @@ -949,6 +991,7 @@ Once a socket is assigned to this request and is connected [`socket.setNoDelay()`][] will be called. ### `request.setSocketKeepAlive([enable][, initialDelay])` + <!-- YAML added: v0.5.9 --> @@ -960,6 +1003,7 @@ Once a socket is assigned to this request and is connected [`socket.setKeepAlive()`][] will be called. ### `request.setTimeout(timeout[, callback])` + <!-- YAML added: v0.5.9 changes: @@ -977,6 +1021,7 @@ Once a socket is assigned to this request and is connected [`socket.setTimeout()`][] will be called. ### `request.socket` + <!-- YAML added: v0.3.0 --> @@ -1007,6 +1052,7 @@ a subclass of {stream.Duplex}, unless the user specified a socket type other than {net.Socket}. ### `request.writableEnded` + <!-- YAML added: v12.9.0 --> @@ -1018,6 +1064,7 @@ does not indicate whether the data has been flushed, for this use [`request.writableFinished`][] instead. ### `request.writableFinished` + <!-- YAML added: v12.7.0 --> @@ -1028,6 +1075,7 @@ Is `true` if all data has been flushed to the underlying system, immediately before the [`'finish'`][] event is emitted. ### `request.write(chunk[, encoding][, callback])` + <!-- YAML added: v0.1.29 --> @@ -1057,6 +1105,7 @@ When `write` function is called with empty string or buffer, it does nothing and waits for more input. ## Class: `http.Server` + <!-- YAML added: v0.1.17 --> @@ -1064,6 +1113,7 @@ added: v0.1.17 * Extends: {net.Server} ### Event: `'checkContinue'` + <!-- YAML added: v0.3.0 --> @@ -1084,6 +1134,7 @@ When this event is emitted and handled, the [`'request'`][] event will not be emitted. ### Event: `'checkExpectation'` + <!-- YAML added: v5.5.0 --> @@ -1099,6 +1150,7 @@ When this event is emitted and handled, the [`'request'`][] event will not be emitted. ### Event: `'clientError'` + <!-- YAML added: v0.1.94 changes: @@ -1151,7 +1203,7 @@ server.listen(8000); When the `'clientError'` event occurs, there is no `request` or `response` object, so any HTTP response sent, including response headers and payload, -*must* be written directly to the `socket` object. Care must be taken to +_must_ be written directly to the `socket` object. Care must be taken to ensure the response is a properly formatted HTTP response message. `err` is an instance of `Error` with two extra columns: @@ -1176,6 +1228,7 @@ server.on('clientError', (err, socket) => { ``` ### Event: `'close'` + <!-- YAML added: v0.1.4 --> @@ -1183,6 +1236,7 @@ added: v0.1.4 Emitted when the server closes. ### Event: `'connect'` + <!-- YAML added: v0.7.0 --> @@ -1205,6 +1259,7 @@ event listener, meaning it will need to be bound in order to handle data sent to the server on that socket. ### Event: `'connection'` + <!-- YAML added: v0.1.0 --> @@ -1229,6 +1284,7 @@ a subclass of {stream.Duplex}, unless the user specifies a socket type other than {net.Socket}. ### Event: `'request'` + <!-- YAML added: v0.1.0 --> @@ -1240,6 +1296,7 @@ Emitted each time there is a request. There may be multiple requests per connection (in the case of HTTP Keep-Alive connections). ### Event: `'upgrade'` + <!-- YAML added: v0.1.94 changes: @@ -1266,6 +1323,7 @@ a subclass of {stream.Duplex}, unless the user specifies a socket type other than {net.Socket}. ### `server.close([callback])` + <!-- YAML added: v0.1.90 --> @@ -1275,6 +1333,7 @@ added: v0.1.90 Stops the server from accepting new connections. See [`net.Server.close()`][]. ### `server.headersTimeout` + <!-- YAML added: - v11.3.0 @@ -1302,6 +1361,7 @@ Starts the HTTP server listening for connections. This method is identical to [`server.listen()`][] from [`net.Server`][]. ### `server.listening` + <!-- YAML added: v5.7.0 --> @@ -1309,6 +1369,7 @@ added: v5.7.0 * {boolean} Indicates whether or not the server is listening for connections. ### `server.maxHeadersCount` + <!-- YAML added: v0.7.0 --> @@ -1318,6 +1379,7 @@ added: v0.7.0 Limits maximum incoming headers count. If set to 0, no limit will be applied. ### `server.requestTimeout` + <!-- YAML added: v14.11.0 --> @@ -1335,6 +1397,7 @@ potential Denial-of-Service attacks in case the server is deployed without a reverse proxy in front. ### `server.setTimeout([msecs][, callback])` + <!-- YAML added: v0.9.12 changes: @@ -1359,6 +1422,7 @@ is assigned to the Server's `'timeout'` event, timeouts must be handled explicitly. ### `server.maxRequestsPerSocket` + <!-- YAML added: v16.10.0 --> @@ -1375,6 +1439,7 @@ but will not actually close the connection, subsequent requests sent after the limit is reached will get `503 Service Unavailable` as a response. ### `server.timeout` + <!-- YAML added: v0.9.12 changes: @@ -1394,6 +1459,7 @@ The socket timeout logic is set up on connection, so changing this value only affects new connections to the server, not any existing connections. ### `server.keepAliveTimeout` + <!-- YAML added: v8.0.0 --> @@ -1415,6 +1481,7 @@ The socket timeout logic is set up on connection, so changing this value only affects new connections to the server, not any existing connections. ## Class: `http.ServerResponse` + <!-- YAML added: v0.1.17 --> @@ -1425,6 +1492,7 @@ This object is created internally by an HTTP server, not by the user. It is passed as the second parameter to the [`'request'`][] event. ### Event: `'close'` + <!-- YAML added: v0.6.7 --> @@ -1433,6 +1501,7 @@ Indicates that the response is completed, or its underlying connection was terminated prematurely (before the response completion). ### Event: `'finish'` + <!-- YAML added: v0.3.6 --> @@ -1443,6 +1512,7 @@ handed off to the operating system for transmission over the network. It does not imply that the client has received anything yet. ### `response.addTrailers(headers)` + <!-- YAML added: v0.3.0 --> @@ -1471,6 +1541,7 @@ Attempting to set a header field name or value that contains invalid characters will result in a [`TypeError`][] being thrown. ### `response.connection` + <!-- YAML added: v0.3.0 deprecated: v13.0.0 @@ -1483,6 +1554,7 @@ deprecated: v13.0.0 See [`response.socket`][]. ### `response.cork()` + <!-- YAML added: - v13.2.0 @@ -1492,6 +1564,7 @@ added: See [`writable.cork()`][]. ### `response.end([data[, encoding]][, callback])` + <!-- YAML added: v0.1.90 changes: @@ -1516,6 +1589,7 @@ If `callback` is specified, it will be called when the response stream is finished. ### `response.finished` + <!-- YAML added: v0.0.2 deprecated: @@ -1531,6 +1605,7 @@ The `response.finished` property will be `true` if [`response.end()`][] has been called. ### `response.flushHeaders()` + <!-- YAML added: v1.6.0 --> @@ -1538,6 +1613,7 @@ added: v1.6.0 Flushes the response headers. See also: [`request.flushHeaders()`][]. ### `response.getHeader(name)` + <!-- YAML added: v0.4.0 --> @@ -1562,11 +1638,12 @@ const setCookie = response.getHeader('set-cookie'); ``` ### `response.getHeaderNames()` + <!-- YAML added: v7.7.0 --> -* Returns: {string[]} +* Returns: {string\[]} Returns an array containing the unique names of the current outgoing headers. All header names are lowercase. @@ -1580,6 +1657,7 @@ const headerNames = response.getHeaderNames(); ``` ### `response.getHeaders()` + <!-- YAML added: v7.7.0 --> @@ -1595,7 +1673,7 @@ are lowercase. The object returned by the `response.getHeaders()` method _does not_ prototypically inherit from the JavaScript `Object`. This means that typical `Object` methods such as `obj.toString()`, `obj.hasOwnProperty()`, and others -are not defined and *will not work*. +are not defined and _will not work_. ```js response.setHeader('Foo', 'bar'); @@ -1606,6 +1684,7 @@ const headers = response.getHeaders(); ``` ### `response.hasHeader(name)` + <!-- YAML added: v7.7.0 --> @@ -1621,6 +1700,7 @@ const hasContentType = response.hasHeader('content-type'); ``` ### `response.headersSent` + <!-- YAML added: v0.9.3 --> @@ -1630,6 +1710,7 @@ added: v0.9.3 Boolean (read-only). True if headers were sent, false otherwise. ### `response.removeHeader(name)` + <!-- YAML added: v0.4.0 --> @@ -1643,6 +1724,7 @@ response.removeHeader('Content-Encoding'); ``` ### `response.req` + <!-- YAML added: v15.7.0 --> @@ -1652,6 +1734,7 @@ added: v15.7.0 A reference to the original HTTP `request` object. ### `response.sendDate` + <!-- YAML added: v0.7.5 --> @@ -1665,6 +1748,7 @@ This should only be disabled for testing; HTTP requires the Date header in responses. ### `response.setHeader(name, value)` + <!-- YAML added: v0.4.0 --> @@ -1718,6 +1802,7 @@ is desired with potential future retrieval and modification, use [`response.setHeader()`][] instead of [`response.writeHead()`][]. ### `response.setTimeout(msecs[, callback])` + <!-- YAML added: v0.9.12 --> @@ -1736,6 +1821,7 @@ assigned to the request, the response, or the server's `'timeout'` events, timed out sockets must be handled explicitly. ### `response.socket` + <!-- YAML added: v0.3.0 --> @@ -1761,6 +1847,7 @@ a subclass of {stream.Duplex}, unless the user specified a socket type other than {net.Socket}. ### `response.statusCode` + <!-- YAML added: v0.4.0 --> @@ -1779,6 +1866,7 @@ After response header was sent to the client, this property indicates the status code which was sent out. ### `response.statusMessage` + <!-- YAML added: v0.11.8 --> @@ -1798,6 +1886,7 @@ After response header was sent to the client, this property indicates the status message which was sent out. ### `response.uncork()` + <!-- YAML added: - v13.2.0 @@ -1807,6 +1896,7 @@ added: See [`writable.uncork()`][]. ### `response.writableEnded` + <!-- YAML added: v12.9.0 --> @@ -1818,6 +1908,7 @@ does not indicate whether the data has been flushed, for this use [`response.writableFinished`][] instead. ### `response.writableFinished` + <!-- YAML added: v12.7.0 --> @@ -1828,6 +1919,7 @@ Is `true` if all data has been flushed to the underlying system, immediately before the [`'finish'`][] event is emitted. ### `response.write(chunk[, encoding][, callback])` + <!-- YAML added: v0.1.29 --> @@ -1865,6 +1957,7 @@ buffer. Returns `false` if all or part of the data was queued in user memory. `'drain'` will be emitted when the buffer is free again. ### `response.writeContinue()` + <!-- YAML added: v0.3.0 --> @@ -1874,6 +1967,7 @@ the request body should be sent. See the [`'checkContinue'`][] event on `Server`. ### `response.writeHead(statusCode[, statusMessage][, headers])` + <!-- YAML added: v0.1.30 changes: @@ -1905,7 +1999,7 @@ Optionally one can give a human-readable `statusMessage` as the second argument. `headers` may be an `Array` where the keys and values are in the same list. -It is *not* a list of tuples. So, the even-numbered offsets are key values, +It is _not_ a list of tuples. So, the even-numbered offsets are key values, and the odd-numbered offsets are the associated values. The array is in the same format as `request.rawHeaders`. @@ -1957,6 +2051,7 @@ Attempting to set a header field name or value that contains invalid characters will result in a [`TypeError`][] being thrown. ### `response.writeProcessing()` + <!-- YAML added: v10.0.0 --> @@ -1965,6 +2060,7 @@ Sends a HTTP/1.1 102 Processing message to the client, indicating that the request body should be sent. ## Class: `http.IncomingMessage` + <!-- YAML added: v0.1.17 changes: @@ -1992,6 +2088,7 @@ parse and emit the incoming HTTP headers and payload, as the underlying socket may be reused multiple times in case of keep-alive. ### Event: `'aborted'` + <!-- YAML added: v0.3.8 deprecated: v17.0.0 @@ -2002,6 +2099,7 @@ deprecated: v17.0.0 Emitted when the request has been aborted. ### Event: `'close'` + <!-- YAML added: v0.4.2 --> @@ -2009,6 +2107,7 @@ added: v0.4.2 Indicates that the underlying connection was closed. ### `message.aborted` + <!-- YAML added: v10.1.0 deprecated: v17.0.0 @@ -2022,6 +2121,7 @@ The `message.aborted` property will be `true` if the request has been aborted. ### `message.complete` + <!-- YAML added: v0.3.0 --> @@ -2050,6 +2150,7 @@ const req = http.request({ ``` ### `message.connection` + <!-- YAML added: v0.1.90 deprecated: v16.0.0 @@ -2060,6 +2161,7 @@ deprecated: v16.0.0 Alias for [`message.socket`][]. ### `message.destroy([error])` + <!-- YAML added: v0.3.0 changes: @@ -2079,6 +2181,7 @@ is provided, an `'error'` event is emitted on the socket and `error` is passed as an argument to any listeners on the event. ### `message.headers` + <!-- YAML added: v0.1.5 changes: @@ -2116,6 +2219,7 @@ header name: * For all other headers, the values are joined together with ', '. ### `message.httpVersion` + <!-- YAML added: v0.1.1 --> @@ -2130,6 +2234,7 @@ Also `message.httpVersionMajor` is the first integer and `message.httpVersionMinor` is the second. ### `message.method` + <!-- YAML added: v0.1.1 --> @@ -2141,15 +2246,16 @@ added: v0.1.1 The request method as a string. Read only. Examples: `'GET'`, `'DELETE'`. ### `message.rawHeaders` + <!-- YAML added: v0.11.6 --> -* {string[]} +* {string\[]} The raw request/response headers list exactly as they were received. -The keys and values are in the same list. It is *not* a +The keys and values are in the same list. It is _not_ a list of tuples. So, the even-numbered offsets are key values, and the odd-numbered offsets are the associated values. @@ -2170,16 +2276,18 @@ console.log(request.rawHeaders); ``` ### `message.rawTrailers` + <!-- YAML added: v0.11.6 --> -* {string[]} +* {string\[]} The raw request/response trailer keys and values exactly as they were received. Only populated at the `'end'` event. ### `message.setTimeout(msecs[, callback])` + <!-- YAML added: v0.5.9 --> @@ -2191,6 +2299,7 @@ added: v0.5.9 Calls `message.socket.setTimeout(msecs, callback)`. ### `message.socket` + <!-- YAML added: v0.3.0 --> @@ -2207,6 +2316,7 @@ a subclass of {stream.Duplex}, unless the user specified a socket type other than {net.Socket}. ### `message.statusCode` + <!-- YAML added: v0.1.1 --> @@ -2218,6 +2328,7 @@ added: v0.1.1 The 3-digit HTTP response status code. E.G. `404`. ### `message.statusMessage` + <!-- YAML added: v0.11.10 --> @@ -2230,6 +2341,7 @@ The HTTP response status message (reason phrase). E.G. `OK` or `Internal Server Error`. ### `message.trailers` + <!-- YAML added: v0.3.0 --> @@ -2239,6 +2351,7 @@ added: v0.3.0 The request/response trailers object. Only populated at the `'end'` event. ### `message.url` + <!-- YAML added: v0.1.90 --> @@ -2284,6 +2397,7 @@ URL { ``` ## Class: `http.OutgoingMessage` + <!-- YAML added: v0.1.17 --> @@ -2295,6 +2409,7 @@ and [`http.ServerResponse`][]. It is an abstract of outgoing message from the perspective of the participants of HTTP transaction. ### Event: `drain` + <!-- YAML added: v0.3.6 --> @@ -2302,6 +2417,7 @@ added: v0.3.6 Emitted when the buffer of the message is free again. ### Event: `finish` + <!-- YAML added: v0.1.17 --> @@ -2309,6 +2425,7 @@ added: v0.1.17 Emitted when the transmission is finished successfully. ### Event: `prefinish` + <!-- YAML added: v0.11.6 --> @@ -2318,6 +2435,7 @@ When the event is emitted, all data has been processed but not necessarily completely flushed. ### `outgoingMessage.addTrailers(headers)` + <!-- YAML added: v0.3.0 --> @@ -2344,6 +2462,7 @@ Attempting to set a header field name or value that contains invalid characters will result in a `TypeError` being thrown. ### `outgoingMessage.connection` + <!-- YAML added: v0.3.0 deprecated: @@ -2354,7 +2473,9 @@ deprecated: > Stability: 0 - Deprecated: Use [`outgoingMessage.socket`][] instead. Aliases of `outgoingMessage.socket` + ### `outgoingMessage.cork()` + <!-- YAML added: v14.0.0 --> @@ -2362,6 +2483,7 @@ added: v14.0.0 See [`writable.cork()`][]. ### `outgoingMessage.destroy([error])` + <!-- YAML added: v0.3.0 --> @@ -2373,6 +2495,7 @@ Destroys the message. Once a socket is associated with the message and is connected, that socket will be destroyed as well. ### `outgoingMessage.end(chunk[, encoding][, callback])` + <!-- YAML added: v0.1.90 changes: @@ -2397,6 +2520,7 @@ If `callback` is provided, it will be called when the message is finished. (equivalent to the callback to event `finish`) ### `outgoingMessage.flushHeaders()` + <!-- YAML added: v1.6.0 --> @@ -2413,6 +2537,7 @@ data is not sent until possibly much later. `outgoingMessage.flushHeaders()` bypasses the optimization and kickstarts the request. ### `outgoingMessage.getHeader(name)` + <!-- YAML added: v0.4.0 --> @@ -2424,16 +2549,18 @@ Gets the value of HTTP header with the given name. If such a name doesn't exist in message, it will be `undefined`. ### `outgoingMessage.getHeaderNames()` + <!-- YAML added: v8.0.0 --> -* Returns {string[]} +* Returns {string\[]} Returns an array of names of headers of the outgoing outgoingMessage. All names are lowercase. ### `outgoingMessage.getHeaders()` + <!-- YAML added: v8.0.0 --> @@ -2460,6 +2587,7 @@ const headers = outgoingMessage.getHeaders(); ``` ### `outgoingMessage.hasHeader(name)` + <!-- YAML added: v8.0.0 --> @@ -2475,6 +2603,7 @@ const hasContentType = outgoingMessage.hasHeader('content-type'); ``` ### `outgoingMessage.headersSent` + <!-- YAML added: v0.9.3 --> @@ -2484,6 +2613,7 @@ added: v0.9.3 Read-only. `true` if the headers were sent, otherwise `false`. ### `outgoingMessage.pipe()` + <!-- YAML added: v9.0.0 --> @@ -2498,6 +2628,7 @@ it inherits from `Stream`. The User should not call this function directly. ### `outgoingMessage.removeHeader()` + <!-- YAML added: v0.4.0 --> @@ -2509,6 +2640,7 @@ outgoingMessage.removeHeader('Content-Encoding'); ``` ### `outgoingMessage.setHeader(name, value)` + <!-- YAML added: v0.4.0 --> @@ -2520,6 +2652,7 @@ added: v0.4.0 Sets a single header value for the header object. ### `outgoingMessage.setTimeout(msesc[, callback])` + <!-- YAML added: v0.9.12 --> @@ -2533,6 +2666,7 @@ Once a socket is associated with the message and is connected, [`socket.setTimeout()`][] will be called with `msecs` as the first parameter. ### `outgoingMessage.socket` + <!-- YAML added: v0.3.0 --> @@ -2545,6 +2679,7 @@ this property. After calling `outgoingMessage.end()`, this property will be nulled. ### `outgoingMessage.uncork()` + <!-- YAML added: v14.0.0 --> @@ -2552,6 +2687,7 @@ added: v14.0.0 See [`writable.uncork()`][] ### `outgoingMessage.writableCorked` + <!-- YAML added: v14.0.0 --> @@ -2562,6 +2698,7 @@ This `outgoingMessage.writableCorked` will return the time how many `outgoingMessage.cork()` have been called. ### `outgoingMessage.writableEnded` + <!-- YAML added: v13.0.0 --> @@ -2573,6 +2710,7 @@ this property does not reflect whether the data has been flush. For that purpose, use `message.writableFinished` instead. ### `outgoingMessage.writableFinished` + <!-- YAML added: v13.0.0 --> @@ -2582,6 +2720,7 @@ added: v13.0.0 Readonly. `true` if all data has been flushed to the underlying system. ### `outgoingMessage.writableHighWaterMark` + <!-- YAML added: v13.0.0 --> @@ -2596,6 +2735,7 @@ underlying socket if socket exists. Else, it would be the default buffered by the socket. ### `outgoingMessage.writableLength` + <!-- YAML added: v13.0.0 --> @@ -2606,6 +2746,7 @@ Readonly, This `outgoingMessage.writableLength` contains the number of bytes (or objects) in the buffer ready to send. ### `outgoingMessage.writableObjectMode` + <!-- YAML added: v13.0.0 --> @@ -2615,6 +2756,7 @@ added: v13.0.0 Readonly, always returns `false`. ### `outgoingMessage.write(chunk[, encoding][, callback])` + <!-- YAML added: v0.1.29 changes: @@ -2658,15 +2800,17 @@ buffer. Returns `false` if all or part of the data was queued in the user memory. Event `drain` will be emitted when the buffer is free again. ## `http.METHODS` + <!-- YAML added: v0.11.8 --> -* {string[]} +* {string\[]} A list of the HTTP methods that are supported by the parser. ## `http.STATUS_CODES` + <!-- YAML added: v0.1.22 --> @@ -2678,6 +2822,7 @@ short description of each. For example, `http.STATUS_CODES[404] === 'Not Found'`. ## `http.createServer([options][, requestListener])` + <!-- YAML added: v0.1.13 changes: @@ -2712,6 +2857,7 @@ changes: [`--max-http-header-size`][] for requests received by this server, i.e. the maximum length of request headers in bytes. **Default:** 16384 (16 KB). + * `requestListener` {Function} * Returns: {http.Server} @@ -2753,7 +2899,9 @@ server.listen(8000); ``` ## `http.get(options[, callback])` + ## `http.get(url[, options][, callback])` + <!-- YAML added: v0.3.6 changes: @@ -2833,6 +2981,7 @@ server.listen(8000); ``` ## `http.globalAgent` + <!-- YAML added: v0.5.9 --> @@ -2843,6 +2992,7 @@ Global instance of `Agent` which is used as the default for all HTTP client requests. ## `http.maxHeaderSize` + <!-- YAML added: - v11.6.0 @@ -2859,7 +3009,9 @@ This can be overridden for servers and client requests by passing the `maxHeaderSize` option. ## `http.request(options[, callback])` + ## `http.request(url[, options][, callback])` + <!-- YAML added: v0.3.6 changes: @@ -2940,7 +3092,7 @@ changes: * `setHost` {boolean}: Specifies whether or not to automatically add the `Host` header. Defaults to `true`. * `socketPath` {string} Unix Domain Socket (cannot be used if one of `host` - or `port` is specified, those specify a TCP Socket). + or `port` is specified, those specify a TCP Socket). * `timeout` {number}: A number specifying the socket timeout in milliseconds. This will set the timeout before the socket is connected. * `signal` {AbortSignal}: An AbortSignal that may be used to abort an ongoing @@ -3145,6 +3297,7 @@ Passing an `AbortSignal` and then calling `abort` on the corresponding request itself. ## `http.validateHeaderName(name)` + <!-- YAML added: v14.3.0 --> @@ -3162,6 +3315,7 @@ or response. The HTTP module will automatically validate such headers. Examples: Example: + ```js const { validateHeaderName } = require('http'); @@ -3175,6 +3329,7 @@ try { ``` ## `http.validateHeaderValue(name, value)` + <!-- YAML added: v14.3.0 --> @@ -3186,6 +3341,7 @@ Performs the low-level validations on the provided `value` that are done when `res.setHeader(name, value)` is called. Passing illegal value as `value` will result in a [`TypeError`][] being thrown. + * Undefined value error is identified by `code: 'ERR_HTTP_INVALID_HEADER_VALUE'`. * Invalid value character error is identified by `code: 'ERR_INVALID_CHAR'`. |