undici 6.2.0 → 6.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/agent.js +5 -25
- package/lib/handler/RedirectHandler.js +12 -7
- package/package.json +1 -2
package/lib/agent.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
const { InvalidArgumentError } = require('./core/errors')
|
|
4
|
-
const { kClients, kRunning, kClose, kDestroy, kDispatch, kInterceptors
|
|
4
|
+
const { kClients, kRunning, kClose, kDestroy, kDispatch, kInterceptors } = require('./core/symbols')
|
|
5
5
|
const DispatcherBase = require('./dispatcher-base')
|
|
6
6
|
const Pool = require('./pool')
|
|
7
7
|
const Client = require('./client')
|
|
@@ -15,7 +15,6 @@ const kMaxRedirections = Symbol('maxRedirections')
|
|
|
15
15
|
const kOnDrain = Symbol('onDrain')
|
|
16
16
|
const kFactory = Symbol('factory')
|
|
17
17
|
const kOptions = Symbol('options')
|
|
18
|
-
const kDeleteScheduled = Symbol('deleteScheduled')
|
|
19
18
|
|
|
20
19
|
function defaultFactory (origin, opts) {
|
|
21
20
|
return opts && opts.connections === 1
|
|
@@ -94,34 +93,15 @@ class Agent extends DispatcherBase {
|
|
|
94
93
|
|
|
95
94
|
if (!dispatcher) {
|
|
96
95
|
dispatcher = this[kFactory](opts.origin, this[kOptions])
|
|
97
|
-
.on('drain',
|
|
98
|
-
this[kOnDrain](...args)
|
|
99
|
-
|
|
100
|
-
// We remove the client if it is not busy for 5 minutes
|
|
101
|
-
// to avoid a long list of clients to saturate memory.
|
|
102
|
-
// Ideally, we could use a FinalizationRegistry here, but
|
|
103
|
-
// it is currently very buggy in Node.js.
|
|
104
|
-
// See
|
|
105
|
-
// * https://github.com/nodejs/node/issues/49344
|
|
106
|
-
// * https://github.com/nodejs/node/issues/47748
|
|
107
|
-
// TODO(mcollina): make the timeout configurable or
|
|
108
|
-
// use an event to remove disconnected clients.
|
|
109
|
-
this[kDeleteScheduled] = setTimeout(() => {
|
|
110
|
-
if (dispatcher[kBusy] === 0) {
|
|
111
|
-
this[kClients].destroy().then(() => {})
|
|
112
|
-
this[kClients].delete(key)
|
|
113
|
-
}
|
|
114
|
-
}, 300_000)
|
|
115
|
-
this[kDeleteScheduled].unref()
|
|
116
|
-
})
|
|
96
|
+
.on('drain', this[kOnDrain])
|
|
117
97
|
.on('connect', this[kOnConnect])
|
|
118
98
|
.on('disconnect', this[kOnDisconnect])
|
|
119
99
|
.on('connectionError', this[kOnConnectionError])
|
|
120
100
|
|
|
101
|
+
// This introduces a tiny memory leak, as dispatchers are never removed from the map.
|
|
102
|
+
// TODO(mcollina): remove te timer when the client/pool do not have any more
|
|
103
|
+
// active connections.
|
|
121
104
|
this[kClients].set(key, dispatcher)
|
|
122
|
-
} else if (dispatcher[kDeleteScheduled]) {
|
|
123
|
-
clearTimeout(dispatcher[kDeleteScheduled])
|
|
124
|
-
dispatcher[kDeleteScheduled] = null
|
|
125
105
|
}
|
|
126
106
|
|
|
127
107
|
return dispatcher.dispatch(opts, handler)
|
|
@@ -176,7 +176,7 @@ function parseLocation (statusCode, headers) {
|
|
|
176
176
|
}
|
|
177
177
|
|
|
178
178
|
for (let i = 0; i < headers.length; i += 2) {
|
|
179
|
-
if (headers[i].
|
|
179
|
+
if (headers[i].length === 8 && util.headerNameToString(headers[i]) === 'location') {
|
|
180
180
|
return headers[i + 1]
|
|
181
181
|
}
|
|
182
182
|
}
|
|
@@ -184,12 +184,17 @@ function parseLocation (statusCode, headers) {
|
|
|
184
184
|
|
|
185
185
|
// https://tools.ietf.org/html/rfc7231#section-6.4.4
|
|
186
186
|
function shouldRemoveHeader (header, removeContent, unknownOrigin) {
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
187
|
+
if (header.length === 4) {
|
|
188
|
+
return util.headerNameToString(header) === 'host'
|
|
189
|
+
}
|
|
190
|
+
if (removeContent && util.headerNameToString(header).startsWith('content-')) {
|
|
191
|
+
return true
|
|
192
|
+
}
|
|
193
|
+
if (unknownOrigin && (header.length === 13 || header.length === 6)) {
|
|
194
|
+
const name = util.headerNameToString(header)
|
|
195
|
+
return name === 'authorization' || name === 'cookie'
|
|
196
|
+
}
|
|
197
|
+
return false
|
|
193
198
|
}
|
|
194
199
|
|
|
195
200
|
// https://tools.ietf.org/html/rfc7231#section-6.4
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "undici",
|
|
3
|
-
"version": "6.2.
|
|
3
|
+
"version": "6.2.1",
|
|
4
4
|
"description": "An HTTP/1.1 client, written from scratch for Node.js",
|
|
5
5
|
"homepage": "https://undici.nodejs.org",
|
|
6
6
|
"bugs": {
|
|
@@ -119,7 +119,6 @@
|
|
|
119
119
|
"jsfuzz": "^1.0.15",
|
|
120
120
|
"mitata": "^0.1.6",
|
|
121
121
|
"mocha": "^10.0.0",
|
|
122
|
-
"mockttp": "^3.9.2",
|
|
123
122
|
"p-timeout": "^3.2.0",
|
|
124
123
|
"pre-commit": "^1.2.2",
|
|
125
124
|
"proxy": "^1.0.2",
|