Skip to content

Commit 2d9ae4f

Browse files
mcollinarichardlau
authored andcommitted
1 parent b558e9f commit 2d9ae4f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+7822
-7122
lines changed

deps/undici/src/README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -178,10 +178,6 @@ Implements [fetch](https://fetch.spec.whatwg.org/#fetch-method).
178178

179179
Only supported on Node 16.8+.
180180

181-
This is [experimental](https://nodejs.org/api/documentation.html#documentation_stability_index) and is not yet fully compliant with the Fetch Standard.
182-
We plan to ship breaking changes to this feature until it is out of experimental.
183-
Help us improve the test coverage by following instructions at [nodejs/undici/#951](https://github.com/nodejs/undici/issues/951).
184-
185181
Basic usage example:
186182

187183
```js
@@ -234,9 +230,15 @@ const data = {
234230
},
235231
}
236232

237-
await fetch('https://example.com', { body: data, method: 'POST' })
233+
await fetch('https://example.com', { body: data, method: 'POST', duplex: 'half' })
238234
```
239235

236+
#### `request.duplex`
237+
238+
- half
239+
240+
In this implementation of fetch, `request.duplex` must be set if `request.body` is `ReadableStream` or `Async Iterables`. And fetch requests are currently always be full duplex. More detail refer to [Fetch Standard.](https://fetch.spec.whatwg.org/#dom-requestinit-duplex)
241+
240242
#### `response.body`
241243

242244
Nodejs has two kinds of streams: [web streams](https://nodejs.org/dist/latest-v16.x/docs/api/webstreams.html), which follow the API of the WHATWG web standard found in browsers, and an older Node-specific [streams API](https://nodejs.org/api/stream.html). `response.body` returns a readable web stream. If you would prefer to work with a Node stream you can convert a web stream using `.fromWeb()`.

deps/undici/src/docs/api/Client.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Furthermore, the following options can be passed:
3838
* **maxCachedSessions** `number | null` (optional) - Default: `100` - Maximum number of TLS cached sessions. Use 0 to disable TLS session caching. Default: 100.
3939
* **timeout** `number | null` (optional) - Default `10e3`
4040
* **servername** `string | null` (optional)
41+
* **keepAlive** `boolean | null` (optional) - Default: `true` - TCP keep-alive enabled
42+
* **keepAliveInitialDelay** `number | null` (optional) - Default: `60000` - TCP keep-alive interval for the socket in milliseconds
4143

4244
### Example - Basic Client instantiation
4345

deps/undici/src/docs/api/Connector.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ Once you call `buildConnector`, it will return a connector function, which takes
2424
* **hostname** `string` (required)
2525
* **host** `string` (optional)
2626
* **protocol** `string` (required)
27-
* **port** `number` (required)
27+
* **port** `string` (required)
2828
* **servername** `string` (optional)
29+
* **localAddress** `string | null` (optional) Local address the socket should connect from.
30+
* **httpSocket** `Socket` (optional) Establish secure connection on a given socket rather than creating a new socket. It can only be sent on TLS update.
2931

3032
### Basic example
3133

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# MIME Type Parsing
2+
3+
## `MIMEType` interface
4+
5+
* **type** `string`
6+
* **subtype** `string`
7+
* **parameters** `Map<string, string>`
8+
* **essence** `string`
9+
10+
## `parseMIMEType(input)`
11+
12+
Implements [parse a MIME type](https://mimesniff.spec.whatwg.org/#parse-a-mime-type).
13+
14+
Parses a MIME type, returning its type, subtype, and any associated parameters. If the parser can't parse an input it returns the string literal `'failure'`.
15+
16+
```js
17+
import { parseMIMEType } from 'undici'
18+
19+
parseMIMEType('text/html; charset=gbk')
20+
// {
21+
// type: 'text',
22+
// subtype: 'html',
23+
// parameters: Map(1) { 'charset' => 'gbk' },
24+
// essence: 'text/html'
25+
// }
26+
```
27+
28+
Arguments:
29+
30+
* **input** `string`
31+
32+
Returns: `MIMEType|'failure'`
33+
34+
## `serializeAMimeType(input)`
35+
36+
Implements [serialize a MIME type](https://mimesniff.spec.whatwg.org/#serialize-a-mime-type).
37+
38+
Serializes a MIMEType object.
39+
40+
```js
41+
import { serializeAMimeType } from 'undici'
42+
43+
serializeAMimeType({
44+
type: 'text',
45+
subtype: 'html',
46+
parameters: new Map([['charset', 'gbk']]),
47+
essence: 'text/html'
48+
})
49+
// text/html;charset=gbk
50+
51+
```
52+
53+
Arguments:
54+
55+
* **mimeType** `MIMEType`
56+
57+
Returns: `string`
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
# Cookie Handling
2+
3+
## `Cookie` interface
4+
5+
* **name** `string`
6+
* **value** `string`
7+
* **expires** `Date|number` (optional)
8+
* **maxAge** `number` (optional)
9+
* **domain** `string` (optional)
10+
* **path** `string` (optional)
11+
* **secure** `boolean` (optional)
12+
* **httpOnly** `boolean` (optional)
13+
* **sameSite** `'String'|'Lax'|'None'` (optional)
14+
* **unparsed** `string[]` (optional) Left over attributes that weren't parsed.
15+
16+
## `deleteCookie(headers, name[, attributes])`
17+
18+
Sets the expiry time of the cookie to the unix epoch, causing browsers to delete it when received.
19+
20+
```js
21+
import { deleteCookie, Headers } from 'undici'
22+
23+
const headers = new Headers()
24+
deleteCookie(headers, 'name')
25+
26+
console.log(headers.get('set-cookie')) // name=; Expires=Thu, 01 Jan 1970 00:00:00 GMT
27+
```
28+
29+
Arguments:
30+
31+
* **headers** `Headers`
32+
* **name** `string`
33+
* **attributes** `{ path?: string, domain?: string }` (optional)
34+
35+
Returns: `void`
36+
37+
## `getCookies(headers)`
38+
39+
Parses the `Cookie` header and returns a list of attributes and values.
40+
41+
```js
42+
import { getCookies, Headers } from 'undici'
43+
44+
const headers = new Headers({
45+
cookie: 'get=cookies; and=attributes'
46+
})
47+
48+
console.log(getCookies(headers)) // { get: 'cookies', and: 'attributes' }
49+
```
50+
51+
Arguments:
52+
53+
* **headers** `Headers`
54+
55+
Returns: `Record<string, string>`
56+
57+
## `getSetCookies(headers)`
58+
59+
Parses all `Set-Cookie` headers.
60+
61+
```js
62+
import { getSetCookies, Headers } from 'undici'
63+
64+
const headers = new Headers({ 'set-cookie': 'undici=getSetCookies; Secure' })
65+
66+
console.log(getSetCookies(headers))
67+
// [
68+
// {
69+
// name: 'undici',
70+
// value: 'getSetCookies',
71+
// secure: true
72+
// }
73+
// ]
74+
75+
```
76+
77+
Arguments:
78+
79+
* **headers** `Headers`
80+
81+
Returns: `Cookie[]`
82+
83+
## `setCookie(headers, cookie)`
84+
85+
Appends a cookie to the `Set-Cookie` header.
86+
87+
```js
88+
import { setCookie, Headers } from 'undici'
89+
90+
const headers = new Headers()
91+
setCookie(headers, { name: 'undici', value: 'setCookie' })
92+
93+
console.log(headers.get('Set-Cookie')) // undici=setCookie
94+
```
95+
96+
Arguments:
97+
98+
* **headers** `Headers`
99+
* **cookie** `Cookie`
100+
101+
Returns: `void`

deps/undici/src/docs/api/DiagnosticsChannel.md

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,70 @@ diagnosticsChannel.channel('undici:client:connectError').subscribe(({ error, soc
135135
// connector is a function that creates the socket
136136
console.log(`Connect failed with ${error.message}`)
137137
})
138+
```
139+
140+
## `undici:websocket:open`
141+
142+
This message is published after the client has successfully connected to a server.
143+
144+
```js
145+
import diagnosticsChannel from 'diagnostics_channel'
146+
147+
diagnosticsChannel.channel('undici:websocket:open').subscribe(({ address, protocol, extensions }) => {
148+
console.log(address) // address, family, and port
149+
console.log(protocol) // negotiated subprotocols
150+
console.log(extensions) // negotiated extensions
151+
})
152+
```
153+
154+
## `undici:websocket:close`
155+
156+
This message is published after the connection has closed.
157+
158+
```js
159+
import diagnosticsChannel from 'diagnostics_channel'
160+
161+
diagnosticsChannel.channel('undici:websocket:close').subscribe(({ websocket, code, reason }) => {
162+
console.log(websocket) // the WebSocket object
163+
console.log(code) // the closing status code
164+
console.log(reason) // the closing reason
165+
})
166+
```
167+
168+
## `undici:websocket:socket_error`
169+
170+
This message is published if the socket experiences an error.
171+
172+
```js
173+
import diagnosticsChannel from 'diagnostics_channel'
174+
175+
diagnosticsChannel.channel('undici:websocket:socket_error').subscribe((error) => {
176+
console.log(error)
177+
})
178+
```
179+
180+
## `undici:websocket:ping`
181+
182+
This message is published after the client receives a ping frame, if the connection is not closing.
183+
184+
```js
185+
import diagnosticsChannel from 'diagnostics_channel'
186+
187+
diagnosticsChannel.channel('undici:websocket:ping').subscribe(({ payload }) => {
188+
// a Buffer or undefined, containing the optional application data of the frame
189+
console.log(payload)
190+
})
191+
```
192+
193+
## `undici:websocket:pong`
194+
195+
This message is published after the client receives a pong frame.
196+
197+
```js
198+
import diagnosticsChannel from 'diagnostics_channel'
199+
200+
diagnosticsChannel.channel('undici:websocket:pong').subscribe(({ payload }) => {
201+
// a Buffer or undefined, containing the optional application data of the frame
202+
console.log(payload)
203+
})
204+
```

deps/undici/src/docs/api/Dispatcher.md

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Returns: `void | Promise<ConnectData>` - Only returns a `Promise` if no `callbac
7474
#### Parameter: `ConnectData`
7575

7676
* **statusCode** `number`
77-
* **headers** `http.IncomingHttpHeaders`
77+
* **headers** `Record<string, string | string[]>`
7878
* **socket** `stream.Duplex`
7979
* **opaque** `unknown`
8080

@@ -192,6 +192,7 @@ Returns: `Boolean` - `false` if dispatcher is busy and further dispatch calls wo
192192
* **origin** `string | URL`
193193
* **path** `string`
194194
* **method** `string`
195+
* **reset** `boolean` (optional) - Default: `false` - If `false`, the request will attempt to create a long-living connection by sending the `connection: keep-alive` header,otherwise will attempt to close it immediately after response by sending `connection: close` within the request and closing the socket afterwards.
195196
* **body** `string | Buffer | Uint8Array | stream.Readable | Iterable | AsyncIterable | null` (optional) - Default: `null`
196197
* **headers** `UndiciHeaders | string[]` (optional) - Default: `null`.
197198
* **query** `Record<string, any> | null` (optional) - Default: `null` - Query string params to be embedded in the request URL. Note that both keys and values of query are encoded using `encodeURIComponent`. If for some reason you need to send them unencoded, embed query params into path directly instead.
@@ -382,7 +383,7 @@ Extends: [`RequestOptions`](#parameter-requestoptions)
382383
#### Parameter: PipelineHandlerData
383384

384385
* **statusCode** `number`
385-
* **headers** `IncomingHttpHeaders`
386+
* **headers** `Record<string, string | string[]>`
386387
* **opaque** `unknown`
387388
* **body** `stream.Readable`
388389
* **context** `object`
@@ -476,7 +477,7 @@ The `RequestOptions.method` property should not be value `'CONNECT'`.
476477
#### Parameter: `ResponseData`
477478

478479
* **statusCode** `number`
479-
* **headers** `http.IncomingHttpHeaders` - Note that all header keys are lower-cased, e. g. `content-type`.
480+
* **headers** `Record<string, string | string[]>` - Note that all header keys are lower-cased, e. g. `content-type`.
480481
* **body** `stream.Readable` which also implements [the body mixin from the Fetch Standard](https://fetch.spec.whatwg.org/#body-mixin).
481482
* **trailers** `Record<string, string>` - This object starts out
482483
as empty and will be mutated to contain trailers after `body` has emitted `'end'`.
@@ -630,7 +631,7 @@ try {
630631

631632
A faster version of `Dispatcher.request`. This method expects the second argument `factory` to return a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable) stream which the response will be written to. This improves performance by avoiding creating an intermediate [`stream.Readable`](https://nodejs.org/api/stream.html#stream_readable_streams) stream when the user expects to directly pipe the response body to a [`stream.Writable`](https://nodejs.org/api/stream.html#stream_class_stream_writable) stream.
632633

633-
As demonstrated in [Example 1 - Basic GET stream request](#example-1-basic-get-stream-request), it is recommended to use the `option.opaque` property to avoid creating a closure for the `factory` method. This pattern works well with Node.js Web Frameworks such as [Fastify](https://fastify.io). See [Example 2 - Stream to Fastify Response](#example-2-stream-to-fastify-response) for more details.
634+
As demonstrated in [Example 1 - Basic GET stream request](#example-1---basic-get-stream-request), it is recommended to use the `option.opaque` property to avoid creating a closure for the `factory` method. This pattern works well with Node.js Web Frameworks such as [Fastify](https://fastify.io). See [Example 2 - Stream to Fastify Response](#example-2---stream-to-fastify-response) for more details.
634635

635636
Arguments:
636637

@@ -643,7 +644,7 @@ Returns: `void | Promise<StreamData>` - Only returns a `Promise` if no `callback
643644
#### Parameter: `StreamFactoryData`
644645

645646
* **statusCode** `number`
646-
* **headers** `http.IncomingHttpHeaders`
647+
* **headers** `Record<string, string | string[]>`
647648
* **opaque** `unknown`
648649
* **onInfo** `({statusCode: number, headers: Record<string, string | string[]>}) => void | null` (optional) - Default: `null` - Callback collecting all the info headers (HTTP 100-199) received.
649650

@@ -852,9 +853,9 @@ Emitted when dispatcher is no longer busy.
852853

853854
## Parameter: `UndiciHeaders`
854855

855-
* `http.IncomingHttpHeaders | string[] | null`
856+
* `Record<string, string | string[]> | string[] | null`
856857

857-
Header arguments such as `options.headers` in [`Client.dispatch`](Client.md#clientdispatchoptions-handlers) can be specified in two forms; either as an object specified by the `http.IncomingHttpHeaders` type, or an array of strings. An array representation of a header list must have an even length or an `InvalidArgumentError` will be thrown.
858+
Header arguments such as `options.headers` in [`Client.dispatch`](Client.md#clientdispatchoptions-handlers) can be specified in two forms; either as an object specified by the `Record<string, string | string[]>` (`IncomingHttpHeaders`) type, or an array of strings. An array representation of a header list must have an even length or an `InvalidArgumentError` will be thrown.
858859

859860
Keys are lowercase and values are not modified.
860861

deps/undici/src/docs/api/Fetch.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Fetch
2+
3+
Undici exposes a fetch() method starts the process of fetching a resource from the network.
4+
5+
Documentation and examples can be found on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/fetch).
6+
7+
## File
8+
9+
This API is implemented as per the standard, you can find documentation on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/File)
10+
11+
## FormData
12+
13+
This API is implemented as per the standard, you can find documentation on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/FormData)
14+
15+
## Response
16+
17+
This API is implemented as per the standard, you can find documentation on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Response)
18+
19+
## Request
20+
21+
This API is implemented as per the standard, you can find documentation on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Request)
22+
23+
## Header
24+
25+
This API is implemented as per the standard, you can find documentation on [MDN](https://developer.mozilla.org/en-US/docs/Web/API/Headers)

deps/undici/src/docs/api/MockPool.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ Returns: `MockInterceptor` corresponding to the input options.
6363

6464
We can define the behaviour of an intercepted request with the following options.
6565

66-
* **reply** `(statusCode: number, replyData: string | Buffer | object | MockInterceptor.MockResponseDataHandler, responseOptions?: MockResponseOptions) => MockScope` - define a reply for a matching request. You can define this as a callback to read incoming request data. Default for `responseOptions` is `{}`.
66+
* **reply** `(statusCode: number, replyData: string | Buffer | object | MockInterceptor.MockResponseDataHandler, responseOptions?: MockResponseOptions) => MockScope` - define a reply for a matching request. You can define the replyData as a callback to read incoming request data. Default for `responseOptions` is `{}`.
67+
* **reply** `(callback: MockInterceptor.MockReplyOptionsCallback) => MockScope` - define a reply for a matching request, allowing dynamic mocking of all reply options rather than just the data.
6768
* **replyWithError** `(error: Error) => MockScope` - define an error for a matching request to throw.
6869
* **defaultReplyHeaders** `(headers: Record<string, string>) => MockInterceptor` - define default headers to be included in subsequent replies. These are in addition to headers on a specific reply.
6970
* **defaultReplyTrailers** `(trailers: Record<string, string>) => MockInterceptor` - define default trailers to be included in subsequent replies. These are in addition to trailers on a specific reply.

0 commit comments

Comments
 (0)