Unverified Commit 2f79baf9 authored by Long Zheng's avatar Long Zheng Committed by GitHub

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.
parent 9855fd7b
...@@ -4,19 +4,9 @@ description: Next.js will automatically use HTTP Keep-Alive by default. Learn mo ...@@ -4,19 +4,9 @@ description: Next.js will automatically use HTTP Keep-Alive by default. Learn mo
# Disabling HTTP Keep-Alive # 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: To disable HTTP Keep-Alive for all `fetch()` calls on the server-side, open `next.config.js` and add the `httpAgentOptions` config:
```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`:
```js ```js
module.exports = { module.exports = {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment