Comparing version 6.19.7 to 6.19.8
@@ -28,5 +28,19 @@ 'use strict' | ||
/** | ||
* Calculate the greatest common divisor of two numbers by | ||
* using the Euclidean algorithm. | ||
* | ||
* @param {number} a | ||
* @param {number} b | ||
* @returns {number} | ||
*/ | ||
function getGreatestCommonDivisor (a, b) { | ||
if (b === 0) return a | ||
return getGreatestCommonDivisor(b, a % b) | ||
if (a === 0) return b | ||
while (b !== 0) { | ||
const t = b | ||
b = a % b | ||
a = t | ||
} | ||
return a | ||
} | ||
@@ -109,3 +123,8 @@ | ||
_updateBalancedPoolStats () { | ||
this[kGreatestCommonDivisor] = this[kClients].map(p => p[kWeight]).reduce(getGreatestCommonDivisor, 0) | ||
let result = 0 | ||
for (let i = 0; i < this[kClients].length; i++) { | ||
result = getGreatestCommonDivisor(this[kClients][i][kWeight], result) | ||
} | ||
this[kGreatestCommonDivisor] = result | ||
} | ||
@@ -112,0 +131,0 @@ |
@@ -19,3 +19,3 @@ 'use strict' | ||
const assert = require('node:assert') | ||
const { isErrored } = require('../../core/util') | ||
const { isErrored, isDisturbed } = require('node:stream') | ||
const { isArrayBuffer } = require('node:util/types') | ||
@@ -26,3 +26,16 @@ const { serializeAMimeType } = require('./data-url') | ||
const textEncoder = new TextEncoder() | ||
function noop () {} | ||
const hasFinalizationRegistry = globalThis.FinalizationRegistry && process.version.indexOf('v18') !== 0 | ||
let streamRegistry | ||
if (hasFinalizationRegistry) { | ||
streamRegistry = new FinalizationRegistry((weakRef) => { | ||
const stream = weakRef.deref() | ||
if (stream && !stream.locked && !isDisturbed(stream) && !isErrored(stream)) { | ||
stream.cancel('Response object has been garbage collected').catch(noop) | ||
} | ||
}) | ||
} | ||
// https://fetch.spec.whatwg.org/#concept-bodyinit-extract | ||
@@ -269,3 +282,3 @@ function extractBody (object, keepalive = false) { | ||
function cloneBody (body) { | ||
function cloneBody (instance, body) { | ||
// To clone a body body, run these steps: | ||
@@ -278,2 +291,6 @@ | ||
if (hasFinalizationRegistry) { | ||
streamRegistry.register(instance, new WeakRef(out1)) | ||
} | ||
// 2. Set body’s stream to out1. | ||
@@ -421,3 +438,3 @@ body.stream = out1 | ||
// with a TypeError. | ||
if (bodyUnusable(object[kState].body)) { | ||
if (bodyUnusable(object)) { | ||
throw new TypeError('Body is unusable: Body has already been read') | ||
@@ -462,3 +479,5 @@ } | ||
// https://fetch.spec.whatwg.org/#body-unusable | ||
function bodyUnusable (body) { | ||
function bodyUnusable (object) { | ||
const body = object[kState].body | ||
// An object including the Body interface mixin is | ||
@@ -505,3 +524,6 @@ // said to be unusable if its body is non-null and | ||
cloneBody, | ||
mixinBody | ||
mixinBody, | ||
streamRegistry, | ||
hasFinalizationRegistry, | ||
bodyUnusable | ||
} |
@@ -5,3 +5,3 @@ /* globals AbortController */ | ||
const { extractBody, mixinBody, cloneBody } = require('./body') | ||
const { extractBody, mixinBody, cloneBody, bodyUnusable } = require('./body') | ||
const { Headers, fill: fillHeaders, HeadersList, setHeadersGuard, getHeadersGuard, setHeadersList, getHeadersList } = require('./headers') | ||
@@ -561,3 +561,3 @@ const { FinalizationRegistry } = require('./dispatcher-weakref')() | ||
// 1. If input is unusable, then throw a TypeError. | ||
if (util.isDisturbed(inputBody.stream) || inputBody.stream.locked) { | ||
if (bodyUnusable(input)) { | ||
throw new TypeError( | ||
@@ -764,3 +764,3 @@ 'Cannot construct a Request with a Request object that has already been used.' | ||
// 1. If this is unusable, then throw a TypeError. | ||
if (this.bodyUsed || this.body?.locked) { | ||
if (bodyUnusable(this)) { | ||
throw new TypeError('unusable') | ||
@@ -883,3 +883,3 @@ } | ||
if (request.body != null) { | ||
newRequest.body = cloneBody(request.body) | ||
newRequest.body = cloneBody(newRequest, request.body) | ||
} | ||
@@ -886,0 +886,0 @@ |
'use strict' | ||
const { Headers, HeadersList, fill, getHeadersGuard, setHeadersGuard, setHeadersList } = require('./headers') | ||
const { extractBody, cloneBody, mixinBody } = require('./body') | ||
const { extractBody, cloneBody, mixinBody, hasFinalizationRegistry, streamRegistry, bodyUnusable } = require('./body') | ||
const util = require('../../core/util') | ||
@@ -29,20 +29,5 @@ const nodeUtil = require('node:util') | ||
const { types } = require('node:util') | ||
const { isDisturbed, isErrored } = require('node:stream') | ||
const textEncoder = new TextEncoder('utf-8') | ||
const hasFinalizationRegistry = globalThis.FinalizationRegistry && process.version.indexOf('v18') !== 0 | ||
let registry | ||
if (hasFinalizationRegistry) { | ||
registry = new FinalizationRegistry((weakRef) => { | ||
const stream = weakRef.deref() | ||
if (stream && !stream.locked && !isDisturbed(stream) && !isErrored(stream)) { | ||
stream.cancel('Response object has been garbage collected').catch(noop) | ||
} | ||
}) | ||
} | ||
function noop () {} | ||
// https://fetch.spec.whatwg.org/#response-class | ||
@@ -248,3 +233,3 @@ class Response { | ||
// 1. If this is unusable, then throw a TypeError. | ||
if (this.bodyUsed || this.body?.locked) { | ||
if (bodyUnusable(this)) { | ||
throw webidl.errors.exception({ | ||
@@ -332,3 +317,3 @@ header: 'Response.clone', | ||
if (response.body != null) { | ||
newResponse.body = cloneBody(response.body) | ||
newResponse.body = cloneBody(newResponse, response.body) | ||
} | ||
@@ -538,3 +523,3 @@ | ||
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/FinalizationRegistry | ||
registry.register(response, new WeakRef(innerResponse.body.stream)) | ||
streamRegistry.register(response, new WeakRef(innerResponse.body.stream)) | ||
} | ||
@@ -541,0 +526,0 @@ |
{ | ||
"name": "undici", | ||
"version": "6.19.7", | ||
"version": "6.19.8", | ||
"description": "An HTTP/1.1 client, written from scratch for Node.js", | ||
@@ -5,0 +5,0 @@ "homepage": "https://undici.nodejs.org", |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1133362
23985