undici
Advanced tools
Comparing version 6.2.0 to 6.2.1
'use strict' | ||
const { InvalidArgumentError } = require('./core/errors') | ||
const { kClients, kRunning, kClose, kDestroy, kDispatch, kInterceptors, kBusy } = require('./core/symbols') | ||
const { kClients, kRunning, kClose, kDestroy, kDispatch, kInterceptors } = require('./core/symbols') | ||
const DispatcherBase = require('./dispatcher-base') | ||
@@ -18,3 +18,2 @@ const Pool = require('./pool') | ||
const kOptions = Symbol('options') | ||
const kDeleteScheduled = Symbol('deleteScheduled') | ||
@@ -98,22 +97,3 @@ function defaultFactory (origin, opts) { | ||
dispatcher = this[kFactory](opts.origin, this[kOptions]) | ||
.on('drain', (...args) => { | ||
this[kOnDrain](...args) | ||
// We remove the client if it is not busy for 5 minutes | ||
// to avoid a long list of clients to saturate memory. | ||
// Ideally, we could use a FinalizationRegistry here, but | ||
// it is currently very buggy in Node.js. | ||
// See | ||
// * https://github.com/nodejs/node/issues/49344 | ||
// * https://github.com/nodejs/node/issues/47748 | ||
// TODO(mcollina): make the timeout configurable or | ||
// use an event to remove disconnected clients. | ||
this[kDeleteScheduled] = setTimeout(() => { | ||
if (dispatcher[kBusy] === 0) { | ||
this[kClients].destroy().then(() => {}) | ||
this[kClients].delete(key) | ||
} | ||
}, 300_000) | ||
this[kDeleteScheduled].unref() | ||
}) | ||
.on('drain', this[kOnDrain]) | ||
.on('connect', this[kOnConnect]) | ||
@@ -123,6 +103,6 @@ .on('disconnect', this[kOnDisconnect]) | ||
// This introduces a tiny memory leak, as dispatchers are never removed from the map. | ||
// TODO(mcollina): remove te timer when the client/pool do not have any more | ||
// active connections. | ||
this[kClients].set(key, dispatcher) | ||
} else if (dispatcher[kDeleteScheduled]) { | ||
clearTimeout(dispatcher[kDeleteScheduled]) | ||
dispatcher[kDeleteScheduled] = null | ||
} | ||
@@ -129,0 +109,0 @@ |
@@ -179,3 +179,3 @@ 'use strict' | ||
for (let i = 0; i < headers.length; i += 2) { | ||
if (headers[i].toString().toLowerCase() === 'location') { | ||
if (headers[i].length === 8 && util.headerNameToString(headers[i]) === 'location') { | ||
return headers[i + 1] | ||
@@ -188,8 +188,13 @@ } | ||
function shouldRemoveHeader (header, removeContent, unknownOrigin) { | ||
return ( | ||
(header.length === 4 && header.toString().toLowerCase() === 'host') || | ||
(removeContent && header.toString().toLowerCase().indexOf('content-') === 0) || | ||
(unknownOrigin && header.length === 13 && header.toString().toLowerCase() === 'authorization') || | ||
(unknownOrigin && header.length === 6 && header.toString().toLowerCase() === 'cookie') | ||
) | ||
if (header.length === 4) { | ||
return util.headerNameToString(header) === 'host' | ||
} | ||
if (removeContent && util.headerNameToString(header).startsWith('content-')) { | ||
return true | ||
} | ||
if (unknownOrigin && (header.length === 13 || header.length === 6)) { | ||
const name = util.headerNameToString(header) | ||
return name === 'authorization' || name === 'cookie' | ||
} | ||
return false | ||
} | ||
@@ -196,0 +201,0 @@ |
{ | ||
"name": "undici", | ||
"version": "6.2.0", | ||
"version": "6.2.1", | ||
"description": "An HTTP/1.1 client, written from scratch for Node.js", | ||
@@ -122,3 +122,2 @@ "homepage": "https://undici.nodejs.org", | ||
"mocha": "^10.0.0", | ||
"mockttp": "^3.9.2", | ||
"p-timeout": "^3.2.0", | ||
@@ -125,0 +124,0 @@ "pre-commit": "^1.2.2", |
37
4
1189306
21021