diff --git a/docs/api/Client.md b/docs/api/Client.md index cfc4c393e0f..13fa3280e97 100644 --- a/docs/api/Client.md +++ b/docs/api/Client.md @@ -17,8 +17,8 @@ Returns: `Client` ### Parameter: `ClientOptions` -* **bodyTimeout** `number | null` (optional) - Default: `30e3` - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 30 seconds. -* **headersTimeout** `number | null` (optional) - Default: `30e3` - The amount of time the parser will wait to receive the complete HTTP headers. Defaults to 30 seconds. +* **bodyTimeout** `number | null` (optional) - Default: `120e3` - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 120 seconds. +* **headersTimeout** `number | null` (optional) - Default: `120e3` - The amount of time the parser will wait to receive the complete HTTP headers. Defaults to 120 seconds. * **keepAliveMaxTimeout** `number | null` (optional) - Default: `600e3` - The maximum allowed `keepAliveTimeout` when overridden by *keep-alive* hints from the server. Defaults to 10 minutes. * **keepAliveTimeout** `number | null` (optional) - Default: `4e3` - The timeout after which a socket without active requests will time out. Monitors time between activity on a connected socket. This value may be overridden by *keep-alive* hints from the server. See [MDN: HTTP - Headers - Keep-Alive directives](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive#directives) for more details. Defaults to 4 seconds. * **keepAliveTimeoutThreshold** `number | null` (optional) - Default: `1e3` - A number subtracted from server *keep-alive* hints when overriding `keepAliveTimeout` to account for timing inaccuracies caused by e.g. transport latency. Defaults to 1 second. diff --git a/docs/api/Dispatcher.md b/docs/api/Dispatcher.md index 56b34275209..ea22fbee021 100644 --- a/docs/api/Dispatcher.md +++ b/docs/api/Dispatcher.md @@ -197,8 +197,8 @@ Returns: `Boolean` - `false` if dispatcher is busy and further dispatch calls wo * **idempotent** `boolean` (optional) - Default: `true` if `method` is `'HEAD'` or `'GET'` - Whether the requests can be safely retried or not. If `false` the request won't be sent until all preceding requests in the pipeline has completed. * **blocking** `boolean` (optional) - Default: `false` - Whether the response is expected to take a long time and would end up blocking the pipeline. When this is set to `true` further pipelining will be avoided on the same connection until headers have been received. * **upgrade** `string | null` (optional) - Default: `null` - Upgrade the request. Should be used to specify the kind of upgrade i.e. `'Websocket'`. -* **bodyTimeout** `number | null` (optional) - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 30 seconds. -* **headersTimeout** `number | null` (optional) - The amount of time the parser will wait to receive the complete HTTP headers. Defaults to 30 seconds. +* **bodyTimeout** `number | null` (optional) - The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Defaults to 120 seconds. +* **headersTimeout** `number | null` (optional) - The amount of time the parser will wait to receive the complete HTTP headers. Defaults to 120 seconds. #### Parameter: `DispatchHandler` diff --git a/lib/client.js b/lib/client.js index d3d4cfc705d..f6a11030f74 100644 --- a/lib/client.js +++ b/lib/client.js @@ -193,8 +193,8 @@ class Client extends DispatcherBase { this[kResuming] = 0 // 0, idle, 1, scheduled, 2 resuming this[kNeedDrain] = 0 // 0, idle, 1, scheduled, 2 resuming this[kHostHeader] = `host: ${this[kUrl].hostname}${this[kUrl].port ? `:${this[kUrl].port}` : ''}\r\n` - this[kBodyTimeout] = bodyTimeout != null ? bodyTimeout : 30e3 - this[kHeadersTimeout] = headersTimeout != null ? headersTimeout : 30e3 + this[kBodyTimeout] = bodyTimeout != null ? bodyTimeout : 120e3 + this[kHeadersTimeout] = headersTimeout != null ? headersTimeout : 120e3 this[kStrictContentLength] = strictContentLength == null ? true : strictContentLength this[kMaxRedirections] = maxRedirections this[kMaxRequests] = maxRequestsPerClient diff --git a/test/client-errors.js b/test/client-errors.js index fbda699f4da..e7cc8b485ac 100644 --- a/test/client-errors.js +++ b/test/client-errors.js @@ -410,7 +410,7 @@ test('invalid options throws', (t) => { } try { - new Client(new URL('http://localhost:200'), { idleTimeout: 30e3 }) // eslint-disable-line + new Client(new URL('http://localhost:200'), { idleTimeout: 120e3 }) // eslint-disable-line t.fail() } catch (err) { t.type(err, errors.InvalidArgumentError) @@ -418,7 +418,7 @@ test('invalid options throws', (t) => { } try { - new Client(new URL('http://localhost:200'), { socketTimeout: 30e3 }) // eslint-disable-line + new Client(new URL('http://localhost:200'), { socketTimeout: 120e3 }) // eslint-disable-line t.fail() } catch (err) { t.type(err, errors.InvalidArgumentError) @@ -426,7 +426,7 @@ test('invalid options throws', (t) => { } try { - new Client(new URL('http://localhost:200'), { requestTimeout: 30e3 }) // eslint-disable-line + new Client(new URL('http://localhost:200'), { requestTimeout: 120e3 }) // eslint-disable-line t.fail() } catch (err) { t.type(err, errors.InvalidArgumentError) diff --git a/test/client-keep-alive.js b/test/client-keep-alive.js index b0f81606067..1f865906d6d 100644 --- a/test/client-keep-alive.js +++ b/test/client-keep-alive.js @@ -187,7 +187,7 @@ test('keep-alive threshold', (t) => { const server = createServer((socket) => { socket.write('HTTP/1.1 200 OK\r\n') socket.write('Content-Length: 0\r\n') - socket.write('Keep-Alive: timeout=30s\r\n') + socket.write('Keep-Alive: timeout=120s\r\n') socket.write('Connection: keep-alive\r\n') socket.write('\r\n\r\n') }) @@ -195,7 +195,7 @@ test('keep-alive threshold', (t) => { server.listen(0, () => { const client = new Client(`http://localhost:${server.address().port}`, { - keepAliveTimeout: 30e3, + keepAliveTimeout: 120e3, keepAliveTimeoutThreshold: 29e3 }) t.teardown(client.destroy.bind(client)) @@ -224,7 +224,7 @@ test('keep-alive max keepalive', (t) => { const server = createServer((socket) => { socket.write('HTTP/1.1 200 OK\r\n') socket.write('Content-Length: 0\r\n') - socket.write('Keep-Alive: timeout=30s\r\n') + socket.write('Keep-Alive: timeout=120s\r\n') socket.write('Connection: keep-alive\r\n') socket.write('\r\n\r\n') }) @@ -232,7 +232,7 @@ test('keep-alive max keepalive', (t) => { server.listen(0, () => { const client = new Client(`http://localhost:${server.address().port}`, { - keepAliveTimeout: 30e3, + keepAliveTimeout: 120e3, keepAliveMaxTimeout: 1e3 }) t.teardown(client.destroy.bind(client)) diff --git a/test/request-timeout.js b/test/request-timeout.js index 44707dee616..e1cf586905f 100644 --- a/test/request-timeout.js +++ b/test/request-timeout.js @@ -542,7 +542,7 @@ test('stream custom timeout', (t) => { server.listen(0, () => { const client = new Client(`http://localhost:${server.address().port}`, { - headersTimeout: 30e3 + headersTimeout: 120e3 }) t.teardown(client.destroy.bind(client)) @@ -623,7 +623,7 @@ test('pipeline timeout', (t) => { server.listen(0, () => { const client = new Client(`http://localhost:${server.address().port}`, { - headersTimeout: 30e3 + headersTimeout: 120e3 }) t.teardown(client.destroy.bind(client)) diff --git a/types/client.d.ts b/types/client.d.ts index 22fcb42cfe8..435ff1da359 100644 --- a/types/client.d.ts +++ b/types/client.d.ts @@ -31,9 +31,9 @@ declare namespace Client { connect?: buildConnector.BuildOptions | Function | null; /** The maximum length of request headers in bytes. Default: `16384` (16KiB). */ maxHeaderSize?: number | null; - /** The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Default: `30e3` milliseconds (30s). */ + /** The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use `0` to disable it entirely. Default: `120e3` milliseconds (120s). */ bodyTimeout?: number | null; - /** The amount of time the parser will wait to receive the complete HTTP headers (Node 14 and above only). Default: `30e3` milliseconds (30s). */ + /** The amount of time the parser will wait to receive the complete HTTP headers (Node 14 and above only). Default: `120e3` milliseconds (120s). */ headersTimeout?: number | null; /** If `true`, an error is thrown when the request content-length header doesn't match the length of the request body. Default: `true`. */ strictContentLength?: boolean; diff --git a/types/dispatcher.d.ts b/types/dispatcher.d.ts index 9b2af26e6d2..6b83e58b90e 100644 --- a/types/dispatcher.d.ts +++ b/types/dispatcher.d.ts @@ -51,9 +51,9 @@ declare namespace Dispatcher { idempotent?: boolean; /** Upgrade the request. Should be used to specify the kind of upgrade i.e. `'Websocket'`. Default: `method === 'CONNECT' || null`. */ upgrade?: boolean | string | null; - /** The amount of time the parser will wait to receive the complete HTTP headers. Defaults to 30 seconds. */ + /** The amount of time the parser will wait to receive the complete HTTP headers. Defaults to 120 seconds. */ headersTimeout?: number | null; - /** The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use 0 to disable it entirely. Defaults to 30 seconds. */ + /** The timeout after which a request will time out, in milliseconds. Monitors time between receiving body data. Use 0 to disable it entirely. Defaults to 120 seconds. */ bodyTimeout?: number | null; } export interface ConnectOptions {