◐ Shell
clean mode source ↗

deps: update undici to 7.25.0 · nodejs/node@b39508b

@@ -19,6 +19,93 @@ When you install undici from npm, you get the full library with all of its

1919

additional APIs, and potentially a newer release than what your Node.js version

2020

bundles.

212122+

## Keep `fetch` and `FormData` from the same implementation

23+24+

When you send a `FormData` body, keep `fetch` and `FormData` together from the

25+

same implementation.

26+27+

Use one of these patterns:

28+29+

### Built-in globals

30+31+

```js

32+

const body = new FormData()

33+

body.set('name', 'some')

34+

body.set('someOtherProperty', '8000')

35+36+

await fetch('https://example.com', {

37+

method: 'POST',

38+

body

39+

})

40+

```

41+42+

### `undici` module imports

43+44+

```js

45+

import { fetch, FormData } from 'undici'

46+47+

const body = new FormData()

48+

body.set('name', 'some')

49+

body.set('someOtherProperty', '8000')

50+51+

await fetch('https://example.com', {

52+

method: 'POST',

53+

body

54+

})

55+

```

56+57+

### `undici.install()` globals

58+59+

If you want the installed `undici` package to provide the globals, call

60+

[`install()`](/docs/api/GlobalInstallation.md):

61+62+

```js

63+

import { install } from 'undici'

64+65+

install()

66+67+

const body = new FormData()

68+

body.set('name', 'some')

69+

body.set('someOtherProperty', '8000')

70+71+

await fetch('https://example.com', {

72+

method: 'POST',

73+

body

74+

})

75+

```

76+77+

`install()` replaces the global `fetch`, `Headers`, `Response`, `Request`, and

78+

`FormData` implementations with undici's versions, and also installs undici's

79+

`WebSocket`, `CloseEvent`, `ErrorEvent`, `MessageEvent`, and `EventSource`

80+

globals.

81+82+

Avoid mixing implementations in the same request, for example:

83+84+

```js

85+

import { fetch } from 'undici'

86+87+

const body = new FormData()

88+89+

await fetch('https://example.com', {

90+

method: 'POST',

91+

body

92+

})

93+

```

94+95+

```js

96+

import { FormData } from 'undici'

97+98+

const body = new FormData()

99+100+

await fetch('https://example.com', {

101+

method: 'POST',

102+

body

103+

})

104+

```

105+106+

Those combinations may behave differently across Node.js and undici versions.

107+

Using matching pairs keeps multipart handling predictable.

108+22109

## When you do NOT need to install undici

2311024111

If all of the following are true, you can rely on the built-in globals and skip

@@ -119,12 +206,12 @@ You can always check the exact bundled version at runtime with

119206

`process.versions.undici`.

120207121208

Installing undici from npm does not replace the built-in globals. If you want

122-

your installed version to override the global `fetch`, use

123-

[`setGlobalDispatcher`](/docs/api/GlobalInstallation.md) or import `fetch`

209+

your installed version to replace the global `fetch` and related classes, use

210+

[`install()`](/docs/api/GlobalInstallation.md). Otherwise, import `fetch`

124211

directly from `'undici'`:

125212126213

```js

127-

import { fetch } from 'undici'; // uses your installed version, not the built-in

214+

import { fetch } from 'undici' // uses your installed version, not the built-in

128215

```

129216130217

## Further reading