From 2f79baf94b616e19dad995101768ffffaac4c691 Mon Sep 17 00:00:00 2001 From: Long Zheng Date: Tue, 20 Dec 2022 09:54:12 +1100 Subject: [PATCH] Update disabling-http-keep-alive.md for server-side only (#43374) fixes #43354 It is not possible to specify an `agent` on a single `fetch()` call since the types for `fetch` come from TypeScript where `agent` is not supported as an option. --- .../next.config.js/disabling-http-keep-alive.md | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/docs/api-reference/next.config.js/disabling-http-keep-alive.md b/docs/api-reference/next.config.js/disabling-http-keep-alive.md index bfa79ad3d8b6def..21fb2be489ee129 100644 --- a/docs/api-reference/next.config.js/disabling-http-keep-alive.md +++ b/docs/api-reference/next.config.js/disabling-http-keep-alive.md @@ -4,19 +4,9 @@ description: Next.js will automatically use HTTP Keep-Alive by default. Learn mo # Disabling HTTP Keep-Alive -Next.js automatically polyfills [node-fetch](/docs/basic-features/supported-browsers-features#polyfills) and enables [HTTP Keep-Alive](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive) by default. You may want to disable HTTP Keep-Alive for certain `fetch()` calls or globally. +In Node.js versions prior to 18, Next.js automatically polyfills `fetch()` with [node-fetch](/docs/basic-features/supported-browsers-features#polyfills) and enables [HTTP Keep-Alive](https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Keep-Alive) by default. -For a single `fetch()` call, you can add the agent option: - -```js -import { Agent } from 'https' - -const url = 'https://example.com' -const agent = new Agent({ keepAlive: false }) -fetch(url, { agent }) -``` - -To override all `fetch()` calls globally, you can use `next.config.js`: +To disable HTTP Keep-Alive for all `fetch()` calls on the server-side, open `next.config.js` and add the `httpAgentOptions` config: ```js module.exports = {