Skip to content

Commit 9dee7b9

Browse files
deps: update undici to 7.3.0
PR-URL: #56624 Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com> Reviewed-By: Marco Ippolito <marcoippolito54@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com> Reviewed-By: Ulises Gascón <ulisesgascongonzalez@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 24cae2d commit 9dee7b9

File tree

15 files changed

+622
-524
lines changed

15 files changed

+622
-524
lines changed

deps/undici/src/lib/cache/sqlite-cache-store.js

Lines changed: 88 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,18 @@ const MAX_ENTRY_SIZE = 2 * 1000 * 1000 * 1000
1515
* @implements {CacheStore}
1616
*
1717
* @typedef {{
18-
* id: Readonly<number>
19-
* headers?: Record<string, string | string[]>
20-
* vary?: string | object
21-
* body: string
22-
* } & import('../../types/cache-interceptor.d.ts').default.CacheValue} SqliteStoreValue
18+
* id: Readonly<number>,
19+
* body?: Uint8Array
20+
* statusCode: number
21+
* statusMessage: string
22+
* headers?: string
23+
* vary?: string
24+
* etag?: string
25+
* cacheControlDirectives?: string
26+
* cachedAt: number
27+
* staleAt: number
28+
* deleteAt: number
29+
* }} SqliteStoreValue
2330
*/
2431
module.exports = class SqliteCacheStore {
2532
#maxEntrySize = MAX_ENTRY_SIZE
@@ -61,7 +68,7 @@ module.exports = class SqliteCacheStore {
6168
#countEntriesQuery
6269

6370
/**
64-
* @type {import('node:sqlite').StatementSync}
71+
* @type {import('node:sqlite').StatementSync | null}
6572
*/
6673
#deleteOldValuesQuery
6774

@@ -163,8 +170,7 @@ module.exports = class SqliteCacheStore {
163170
etag = ?,
164171
cacheControlDirectives = ?,
165172
cachedAt = ?,
166-
staleAt = ?,
167-
deleteAt = ?
173+
staleAt = ?
168174
WHERE
169175
id = ?
170176
`)
@@ -182,9 +188,8 @@ module.exports = class SqliteCacheStore {
182188
cacheControlDirectives,
183189
vary,
184190
cachedAt,
185-
staleAt,
186-
deleteAt
187-
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
191+
staleAt
192+
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
188193
`)
189194

190195
this.#deleteByUrlQuery = this.#db.prepare(
@@ -219,36 +224,78 @@ module.exports = class SqliteCacheStore {
219224

220225
/**
221226
* @param {import('../../types/cache-interceptor.d.ts').default.CacheKey} key
222-
* @returns {import('../../types/cache-interceptor.d.ts').default.GetResult | undefined}
227+
* @returns {(import('../../types/cache-interceptor.d.ts').default.GetResult & { body?: Buffer }) | undefined}
223228
*/
224229
get (key) {
225230
assertCacheKey(key)
226231

227232
const value = this.#findValue(key)
233+
return value
234+
? {
235+
body: value.body ? Buffer.from(value.body.buffer) : undefined,
236+
statusCode: value.statusCode,
237+
statusMessage: value.statusMessage,
238+
headers: value.headers ? JSON.parse(value.headers) : undefined,
239+
etag: value.etag ? value.etag : undefined,
240+
vary: value.vary ? JSON.parse(value.vary) : undefined,
241+
cacheControlDirectives: value.cacheControlDirectives
242+
? JSON.parse(value.cacheControlDirectives)
243+
: undefined,
244+
cachedAt: value.cachedAt,
245+
staleAt: value.staleAt,
246+
deleteAt: value.deleteAt
247+
}
248+
: undefined
249+
}
228250

229-
if (!value) {
230-
return undefined
231-
}
251+
/**
252+
* @param {import('../../types/cache-interceptor.d.ts').default.CacheKey} key
253+
* @param {import('../../types/cache-interceptor.d.ts').default.CacheValue & { body: null | Buffer | Array<Buffer>}} value
254+
*/
255+
set (key, value) {
256+
assertCacheKey(key)
232257

233-
/**
234-
* @type {import('../../types/cache-interceptor.d.ts').default.GetResult}
235-
*/
236-
const result = {
237-
body: Buffer.from(value.body),
238-
statusCode: value.statusCode,
239-
statusMessage: value.statusMessage,
240-
headers: value.headers ? JSON.parse(value.headers) : undefined,
241-
etag: value.etag ? value.etag : undefined,
242-
vary: value.vary ?? undefined,
243-
cacheControlDirectives: value.cacheControlDirectives
244-
? JSON.parse(value.cacheControlDirectives)
245-
: undefined,
246-
cachedAt: value.cachedAt,
247-
staleAt: value.staleAt,
248-
deleteAt: value.deleteAt
258+
const url = this.#makeValueUrl(key)
259+
const body = Array.isArray(value.body) ? Buffer.concat(value.body) : value.body
260+
const size = body?.byteLength
261+
262+
if (size && size > this.#maxEntrySize) {
263+
return
249264
}
250265

251-
return result
266+
const existingValue = this.#findValue(key, true)
267+
if (existingValue) {
268+
// Updating an existing response, let's overwrite it
269+
this.#updateValueQuery.run(
270+
body,
271+
value.deleteAt,
272+
value.statusCode,
273+
value.statusMessage,
274+
value.headers ? JSON.stringify(value.headers) : null,
275+
value.etag ? value.etag : null,
276+
value.cacheControlDirectives ? JSON.stringify(value.cacheControlDirectives) : null,
277+
value.cachedAt,
278+
value.staleAt,
279+
existingValue.id
280+
)
281+
} else {
282+
this.#prune()
283+
// New response, let's insert it
284+
this.#insertValueQuery.run(
285+
url,
286+
key.method,
287+
body,
288+
value.deleteAt,
289+
value.statusCode,
290+
value.statusMessage,
291+
value.headers ? JSON.stringify(value.headers) : null,
292+
value.etag ? value.etag : null,
293+
value.cacheControlDirectives ? JSON.stringify(value.cacheControlDirectives) : null,
294+
value.vary ? JSON.stringify(value.vary) : null,
295+
value.cachedAt,
296+
value.staleAt
297+
)
298+
}
252299
}
253300

254301
/**
@@ -260,7 +307,6 @@ module.exports = class SqliteCacheStore {
260307
assertCacheKey(key)
261308
assertCacheValue(value)
262309

263-
const url = this.#makeValueUrl(key)
264310
let size = 0
265311
/**
266312
* @type {Buffer[] | null}
@@ -269,11 +315,8 @@ module.exports = class SqliteCacheStore {
269315
const store = this
270316

271317
return new Writable({
318+
decodeStrings: true,
272319
write (chunk, encoding, callback) {
273-
if (typeof chunk === 'string') {
274-
chunk = Buffer.from(chunk, encoding)
275-
}
276-
277320
size += chunk.byteLength
278321

279322
if (size < store.#maxEntrySize) {
@@ -285,42 +328,7 @@ module.exports = class SqliteCacheStore {
285328
callback()
286329
},
287330
final (callback) {
288-
const existingValue = store.#findValue(key, true)
289-
if (existingValue) {
290-
// Updating an existing response, let's overwrite it
291-
store.#updateValueQuery.run(
292-
Buffer.concat(body),
293-
value.deleteAt,
294-
value.statusCode,
295-
value.statusMessage,
296-
value.headers ? JSON.stringify(value.headers) : null,
297-
value.etag ? value.etag : null,
298-
value.cacheControlDirectives ? JSON.stringify(value.cacheControlDirectives) : null,
299-
value.cachedAt,
300-
value.staleAt,
301-
value.deleteAt,
302-
existingValue.id
303-
)
304-
} else {
305-
store.#prune()
306-
// New response, let's insert it
307-
store.#insertValueQuery.run(
308-
url,
309-
key.method,
310-
Buffer.concat(body),
311-
value.deleteAt,
312-
value.statusCode,
313-
value.statusMessage,
314-
value.headers ? JSON.stringify(value.headers) : null,
315-
value.etag ? value.etag : null,
316-
value.cacheControlDirectives ? JSON.stringify(value.cacheControlDirectives) : null,
317-
value.vary ? JSON.stringify(value.vary) : null,
318-
value.cachedAt,
319-
value.staleAt,
320-
value.deleteAt
321-
)
322-
}
323-
331+
store.set(key, { ...value, body })
324332
callback()
325333
}
326334
})
@@ -344,14 +352,14 @@ module.exports = class SqliteCacheStore {
344352

345353
{
346354
const removed = this.#deleteExpiredValuesQuery.run(Date.now()).changes
347-
if (removed > 0) {
355+
if (removed) {
348356
return removed
349357
}
350358
}
351359

352360
{
353-
const removed = this.#deleteOldValuesQuery.run(Math.max(Math.floor(this.#maxCount * 0.1), 1)).changes
354-
if (removed > 0) {
361+
const removed = this.#deleteOldValuesQuery?.run(Math.max(Math.floor(this.#maxCount * 0.1), 1)).changes
362+
if (removed) {
355363
return removed
356364
}
357365
}
@@ -379,7 +387,7 @@ module.exports = class SqliteCacheStore {
379387
/**
380388
* @param {import('../../types/cache-interceptor.d.ts').default.CacheKey} key
381389
* @param {boolean} [canBeExpired=false]
382-
* @returns {(SqliteStoreValue & { vary?: Record<string, string[]> }) | undefined}
390+
* @returns {SqliteStoreValue | undefined}
383391
*/
384392
#findValue (key, canBeExpired = false) {
385393
const url = this.#makeValueUrl(key)
@@ -407,10 +415,10 @@ module.exports = class SqliteCacheStore {
407415
return undefined
408416
}
409417

410-
value.vary = JSON.parse(value.vary)
418+
const vary = JSON.parse(value.vary)
411419

412-
for (const header in value.vary) {
413-
if (!headerValueEquals(headers[header], value.vary[header])) {
420+
for (const header in vary) {
421+
if (!headerValueEquals(headers[header], vary[header])) {
414422
matches = false
415423
break
416424
}

deps/undici/src/lib/core/util.js

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -600,20 +600,25 @@ function ReadableStreamFrom (iterable) {
600600
async start () {
601601
iterator = iterable[Symbol.asyncIterator]()
602602
},
603-
async pull (controller) {
604-
const { done, value } = await iterator.next()
605-
if (done) {
606-
queueMicrotask(() => {
607-
controller.close()
608-
controller.byobRequest?.respond(0)
609-
})
610-
} else {
611-
const buf = Buffer.isBuffer(value) ? value : Buffer.from(value)
612-
if (buf.byteLength) {
613-
controller.enqueue(new Uint8Array(buf))
603+
pull (controller) {
604+
async function pull () {
605+
const { done, value } = await iterator.next()
606+
if (done) {
607+
queueMicrotask(() => {
608+
controller.close()
609+
controller.byobRequest?.respond(0)
610+
})
611+
} else {
612+
const buf = Buffer.isBuffer(value) ? value : Buffer.from(value)
613+
if (buf.byteLength) {
614+
controller.enqueue(new Uint8Array(buf))
615+
} else {
616+
return await pull()
617+
}
614618
}
615619
}
616-
return controller.desiredSize > 0
620+
621+
return pull()
617622
},
618623
async cancel () {
619624
await iterator.return()

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy