Skip to content

Commit

Permalink
deps: update undici to 6.15.0
Browse files Browse the repository at this point in the history
  • Loading branch information
nodejs-github-bot committed Apr 29, 2024
1 parent 2299e11 commit 4bcd906
Show file tree
Hide file tree
Showing 25 changed files with 9,315 additions and 8,775 deletions.
13 changes: 12 additions & 1 deletion deps/undici/src/index-fetch.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
'use strict'

const { getGlobalDispatcher, setGlobalDispatcher } = require('./lib/global')
const EnvHttpProxyAgent = require('./lib/dispatcher/env-http-proxy-agent')
const fetchImpl = require('./lib/web/fetch').fetch

module.exports.fetch = function fetch (resource, init = undefined) {
Expand All @@ -15,7 +17,16 @@ module.exports.Headers = require('./lib/web/fetch/headers').Headers
module.exports.Response = require('./lib/web/fetch/response').Response
module.exports.Request = require('./lib/web/fetch/request').Request

const { CloseEvent, ErrorEvent, MessageEvent, createFastMessageEvent } = require('./lib/web/websocket/events')
module.exports.WebSocket = require('./lib/web/websocket/websocket').WebSocket
module.exports.MessageEvent = require('./lib/web/websocket/events').MessageEvent
module.exports.CloseEvent = CloseEvent
module.exports.ErrorEvent = ErrorEvent
module.exports.MessageEvent = MessageEvent
module.exports.createFastMessageEvent = createFastMessageEvent

module.exports.EventSource = require('./lib/web/eventsource/eventsource').EventSource

// Expose the fetch implementation to be enabled in Node.js core via a flag
module.exports.EnvHttpProxyAgent = EnvHttpProxyAgent
module.exports.getGlobalDispatcher = getGlobalDispatcher
module.exports.setGlobalDispatcher = setGlobalDispatcher
35 changes: 21 additions & 14 deletions deps/undici/src/lib/handler/retry-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ const { isDisturbed, parseHeaders, parseRangeHeader } = require('../core/util')

function calculateRetryAfterHeader (retryAfter) {
const current = Date.now()
const diff = new Date(retryAfter).getTime() - current

return diff
return new Date(retryAfter).getTime() - current
}

class RetryHandler {
Expand Down Expand Up @@ -116,11 +114,7 @@ class RetryHandler {
const { counter } = state

// Any code that is not a Undici's originated and allowed to retry
if (
code &&
code !== 'UND_ERR_REQ_RETRY' &&
!errorCodes.includes(code)
) {
if (code && code !== 'UND_ERR_REQ_RETRY' && !errorCodes.includes(code)) {
cb(err)
return
}
Expand Down Expand Up @@ -246,10 +240,7 @@ class RetryHandler {
start != null && Number.isFinite(start),
'content-range mismatch'
)
assert(
end != null && Number.isFinite(end),
'invalid content-length'
)
assert(end != null && Number.isFinite(end), 'invalid content-length')

this.start = start
this.end = end
Expand All @@ -270,6 +261,13 @@ class RetryHandler {
this.resume = resume
this.etag = headers.etag != null ? headers.etag : null

// Weak etags are not useful for comparison nor cache
// for instance not safe to assume if the response is byte-per-byte
// equal
if (this.etag != null && this.etag.startsWith('W/')) {
this.etag = null
}

return this.handler.onHeaders(
statusCode,
rawHeaders,
Expand Down Expand Up @@ -308,7 +306,9 @@ class RetryHandler {
// and server error response
if (this.retryCount - this.retryCountCheckpoint > 0) {
// We count the difference between the last checkpoint and the current retry count
this.retryCount = this.retryCountCheckpoint + (this.retryCount - this.retryCountCheckpoint)
this.retryCount =
this.retryCountCheckpoint +
(this.retryCount - this.retryCountCheckpoint)
} else {
this.retryCount += 1
}
Expand All @@ -328,11 +328,18 @@ class RetryHandler {
}

if (this.start !== 0) {
const headers = { range: `bytes=${this.start}-${this.end ?? ''}` }

// Weak etag check - weak etags will make comparison algorithms never match
if (this.etag != null) {
headers['if-match'] = this.etag
}

this.opts = {
...this.opts,
headers: {
...this.opts.headers,
range: `bytes=${this.start}-${this.end ?? ''}`
...headers
}
}
}
Expand Down
65 changes: 39 additions & 26 deletions deps/undici/src/lib/web/cache/cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,12 @@ class Cache {

async match (request, options = {}) {
webidl.brandCheck(this, Cache)
webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.match' })

request = webidl.converters.RequestInfo(request)
options = webidl.converters.CacheQueryOptions(options)
const prefix = 'Cache.match'
webidl.argumentLengthCheck(arguments, 1, prefix)

request = webidl.converters.RequestInfo(request, prefix, 'request')
options = webidl.converters.CacheQueryOptions(options, prefix, 'options')

const p = this.#internalMatchAll(request, options, 1)

Expand All @@ -59,17 +61,20 @@ class Cache {
async matchAll (request = undefined, options = {}) {
webidl.brandCheck(this, Cache)

if (request !== undefined) request = webidl.converters.RequestInfo(request)
options = webidl.converters.CacheQueryOptions(options)
const prefix = 'Cache.matchAll'
if (request !== undefined) request = webidl.converters.RequestInfo(request, prefix, 'request')
options = webidl.converters.CacheQueryOptions(options, prefix, 'options')

return this.#internalMatchAll(request, options)
}

async add (request) {
webidl.brandCheck(this, Cache)
webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.add' })

request = webidl.converters.RequestInfo(request)
const prefix = 'Cache.add'
webidl.argumentLengthCheck(arguments, 1, prefix)

request = webidl.converters.RequestInfo(request, prefix, 'request')

// 1.
const requests = [request]
Expand All @@ -83,7 +88,9 @@ class Cache {

async addAll (requests) {
webidl.brandCheck(this, Cache)
webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.addAll' })

const prefix = 'Cache.addAll'
webidl.argumentLengthCheck(arguments, 1, prefix)

// 1.
const responsePromises = []
Expand All @@ -95,7 +102,7 @@ class Cache {
for (let request of requests) {
if (request === undefined) {
throw webidl.errors.conversionFailed({
prefix: 'Cache.addAll',
prefix,
argument: 'Argument 1',
types: ['undefined is not allowed']
})
Expand All @@ -113,7 +120,7 @@ class Cache {
// 3.2
if (!urlIsHttpHttpsScheme(r.url) || r.method !== 'GET') {
throw webidl.errors.exception({
header: 'Cache.addAll',
header: prefix,
message: 'Expected http/s scheme when method is not GET.'
})
}
Expand All @@ -131,7 +138,7 @@ class Cache {
// 5.2
if (!urlIsHttpHttpsScheme(r.url)) {
throw webidl.errors.exception({
header: 'Cache.addAll',
header: prefix,
message: 'Expected http/s scheme.'
})
}
Expand Down Expand Up @@ -251,10 +258,12 @@ class Cache {

async put (request, response) {
webidl.brandCheck(this, Cache)
webidl.argumentLengthCheck(arguments, 2, { header: 'Cache.put' })

request = webidl.converters.RequestInfo(request)
response = webidl.converters.Response(response)
const prefix = 'Cache.put'
webidl.argumentLengthCheck(arguments, 2, prefix)

request = webidl.converters.RequestInfo(request, prefix, 'request')
response = webidl.converters.Response(response, prefix, 'response')

// 1.
let innerRequest = null
Expand All @@ -269,7 +278,7 @@ class Cache {
// 4.
if (!urlIsHttpHttpsScheme(innerRequest.url) || innerRequest.method !== 'GET') {
throw webidl.errors.exception({
header: 'Cache.put',
header: prefix,
message: 'Expected an http/s scheme when method is not GET'
})
}
Expand All @@ -280,7 +289,7 @@ class Cache {
// 6.
if (innerResponse.status === 206) {
throw webidl.errors.exception({
header: 'Cache.put',
header: prefix,
message: 'Got 206 status'
})
}
Expand All @@ -295,7 +304,7 @@ class Cache {
// 7.2.1
if (fieldValue === '*') {
throw webidl.errors.exception({
header: 'Cache.put',
header: prefix,
message: 'Got * vary field value'
})
}
Expand All @@ -305,7 +314,7 @@ class Cache {
// 8.
if (innerResponse.body && (isDisturbed(innerResponse.body.stream) || innerResponse.body.stream.locked)) {
throw webidl.errors.exception({
header: 'Cache.put',
header: prefix,
message: 'Response body is locked or disturbed'
})
}
Expand Down Expand Up @@ -380,10 +389,12 @@ class Cache {

async delete (request, options = {}) {
webidl.brandCheck(this, Cache)
webidl.argumentLengthCheck(arguments, 1, { header: 'Cache.delete' })

request = webidl.converters.RequestInfo(request)
options = webidl.converters.CacheQueryOptions(options)
const prefix = 'Cache.delete'
webidl.argumentLengthCheck(arguments, 1, prefix)

request = webidl.converters.RequestInfo(request, prefix, 'request')
options = webidl.converters.CacheQueryOptions(options, prefix, 'options')

/**
* @type {Request}
Expand Down Expand Up @@ -445,8 +456,10 @@ class Cache {
async keys (request = undefined, options = {}) {
webidl.brandCheck(this, Cache)

if (request !== undefined) request = webidl.converters.RequestInfo(request)
options = webidl.converters.CacheQueryOptions(options)
const prefix = 'Cache.keys'

if (request !== undefined) request = webidl.converters.RequestInfo(request, prefix, 'request')
options = webidl.converters.CacheQueryOptions(options, prefix, 'options')

// 1.
let r = null
Expand Down Expand Up @@ -810,17 +823,17 @@ const cacheQueryOptionConverters = [
{
key: 'ignoreSearch',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
},
{
key: 'ignoreMethod',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
},
{
key: 'ignoreVary',
converter: webidl.converters.boolean,
defaultValue: false
defaultValue: () => false
}
]

Expand Down
20 changes: 13 additions & 7 deletions deps/undici/src/lib/web/cache/cachestorage.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class CacheStorage {

async match (request, options = {}) {
webidl.brandCheck(this, CacheStorage)
webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.match' })
webidl.argumentLengthCheck(arguments, 1, 'CacheStorage.match')

request = webidl.converters.RequestInfo(request)
options = webidl.converters.MultiCacheQueryOptions(options)
Expand Down Expand Up @@ -57,9 +57,11 @@ class CacheStorage {
*/
async has (cacheName) {
webidl.brandCheck(this, CacheStorage)
webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.has' })

cacheName = webidl.converters.DOMString(cacheName)
const prefix = 'CacheStorage.has'
webidl.argumentLengthCheck(arguments, 1, prefix)

cacheName = webidl.converters.DOMString(cacheName, prefix, 'cacheName')

// 2.1.1
// 2.2
Expand All @@ -73,9 +75,11 @@ class CacheStorage {
*/
async open (cacheName) {
webidl.brandCheck(this, CacheStorage)
webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.open' })

cacheName = webidl.converters.DOMString(cacheName)
const prefix = 'CacheStorage.open'
webidl.argumentLengthCheck(arguments, 1, prefix)

cacheName = webidl.converters.DOMString(cacheName, prefix, 'cacheName')

// 2.1
if (this.#caches.has(cacheName)) {
Expand Down Expand Up @@ -105,9 +109,11 @@ class CacheStorage {
*/
async delete (cacheName) {
webidl.brandCheck(this, CacheStorage)
webidl.argumentLengthCheck(arguments, 1, { header: 'CacheStorage.delete' })

cacheName = webidl.converters.DOMString(cacheName)
const prefix = 'CacheStorage.delete'
webidl.argumentLengthCheck(arguments, 1, prefix)

cacheName = webidl.converters.DOMString(cacheName, prefix, 'cacheName')

return this.#caches.delete(cacheName)
}
Expand Down
Loading

0 comments on commit 4bcd906

Please sign in to comment.