Skip to content

Commit 00302fc

Browse files
nodejs-github-botjuanarbol
authored andcommitted
deps: update undici to 5.15.0
PR-URL: #46213 Reviewed-By: Richard Lau <rlau@redhat.com> Reviewed-By: Yagiz Nizipli <yagiz@nizipli.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 8393ebc commit 00302fc

37 files changed

+5300
-527
lines changed

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

+101
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

+67
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

+1
Original file line numberDiff line numberDiff line change
@@ -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.

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

+25
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/WebSocket.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Class: WebSocket
2+
3+
> ⚠️ Warning: the WebSocket API is experimental and has known bugs.
4+
5+
Extends: [`EventTarget`](https://developer.mozilla.org/en-US/docs/Web/API/EventTarget)
6+
7+
The WebSocket object provides a way to manage a WebSocket connection to a server, allowing bidirectional communication. The API follows the [WebSocket spec](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket).
8+
9+
## `new WebSocket(url[, protocol])`
10+
11+
Arguments:
12+
13+
* **url** `URL | string` - The url's protocol *must* be `ws` or `wss`.
14+
* **protocol** `string | string[]` (optional) - Subprotocol(s) to request the server use.
15+
16+
## Read More
17+
18+
- [MDN - WebSocket](https://developer.mozilla.org/en-US/docs/Web/API/WebSocket)
19+
- [The WebSocket Specification](https://www.rfc-editor.org/rfc/rfc6455)
20+
- [The WHATWG WebSocket Specification](https://websockets.spec.whatwg.org/)

deps/undici/src/index.d.ts

+2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ import mockErrors from'./types/mock-errors'
1616
import ProxyAgent from'./types/proxy-agent'
1717
import { request, pipeline, stream, connect, upgrade } from './types/api'
1818

19+
export * from './types/cookies'
1920
export * from './types/fetch'
2021
export * from './types/file'
2122
export * from './types/filereader'
2223
export * from './types/formdata'
2324
export * from './types/diagnostics-channel'
25+
export * from './types/websocket'
2426
export { Interceptable } from './types/mock-interceptor'
2527

2628
export { Dispatcher, BalancedPool, Pool, Client, buildConnector, errors, Agent, request, stream, pipeline, connect, upgrade, setGlobalDispatcher, getGlobalDispatcher, setGlobalOrigin, getGlobalOrigin, MockClient, MockPool, MockAgent, mockErrors, ProxyAgent, RedirectHandler, DecoratorHandler }

deps/undici/src/index.js

+15
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,21 @@ if (nodeMajor > 16 || (nodeMajor === 16 && nodeMinor >= 8)) {
119119
module.exports.getGlobalOrigin = getGlobalOrigin
120120
}
121121

122+
if (nodeMajor >= 16) {
123+
const { deleteCookie, getCookies, getSetCookies, setCookie } = require('./lib/cookies')
124+
125+
module.exports.deleteCookie = deleteCookie
126+
module.exports.getCookies = getCookies
127+
module.exports.getSetCookies = getSetCookies
128+
module.exports.setCookie = setCookie
129+
}
130+
131+
if (nodeMajor >= 18) {
132+
const { WebSocket } = require('./lib/websocket/websocket')
133+
134+
module.exports.WebSocket = WebSocket
135+
}
136+
122137
module.exports.request = makeDispatcher(api.request)
123138
module.exports.stream = makeDispatcher(api.stream)
124139
module.exports.pipeline = makeDispatcher(api.pipeline)

deps/undici/src/lib/client.js

+6-3
Original file line numberDiff line numberDiff line change
@@ -1295,7 +1295,7 @@ function _resume (client, sync) {
12951295
}
12961296

12971297
function write (client, request) {
1298-
const { body, method, path, host, upgrade, headers, blocking } = request
1298+
const { body, method, path, host, upgrade, headers, blocking, reset } = request
12991299

13001300
// https://tools.ietf.org/html/rfc7231#section-4.3.1
13011301
// https://tools.ietf.org/html/rfc7231#section-4.3.2
@@ -1363,7 +1363,6 @@ function write (client, request) {
13631363

13641364
if (method === 'HEAD') {
13651365
// https://github.com/mcollina/undici/issues/258
1366-
13671366
// Close after a HEAD request to interop with misbehaving servers
13681367
// that may send a body in the response.
13691368

@@ -1377,6 +1376,10 @@ function write (client, request) {
13771376
socket[kReset] = true
13781377
}
13791378

1379+
if (reset) {
1380+
socket[kReset] = true
1381+
}
1382+
13801383
if (client[kMaxRequests] && socket[kCounter]++ >= client[kMaxRequests]) {
13811384
socket[kReset] = true
13821385
}
@@ -1395,7 +1398,7 @@ function write (client, request) {
13951398

13961399
if (upgrade) {
13971400
header += `connection: upgrade\r\nupgrade: ${upgrade}\r\n`
1398-
} else if (client[kPipelining]) {
1401+
} else if (client[kPipelining] && !socket[kReset]) {
13991402
header += 'connection: keep-alive\r\n'
14001403
} else {
14011404
header += 'connection: close\r\n'
+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
'use strict'
2+
3+
// https://wicg.github.io/cookie-store/#cookie-maximum-attribute-value-size
4+
const maxAttributeValueSize = 1024
5+
6+
// https://wicg.github.io/cookie-store/#cookie-maximum-name-value-pair-size
7+
const maxNameValuePairSize = 4096
8+
9+
module.exports = {
10+
maxAttributeValueSize,
11+
maxNameValuePairSize
12+
}

0 commit comments

Comments
 (0)