@nxtedition/lib 21.5.8 → 21.5.9
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/http.js +9 -0
- package/package.json +1 -1
package/http.js
CHANGED
|
@@ -115,6 +115,8 @@ export class Context {
|
|
|
115
115
|
|
|
116
116
|
function noop() {}
|
|
117
117
|
|
|
118
|
+
const pendingSet = (globalThis._nxt_lib_http_pending ??= new Set())
|
|
119
|
+
|
|
118
120
|
export async function request2(ctx, next) {
|
|
119
121
|
const { req, res, logger } = ctx
|
|
120
122
|
const startTime = performance.now()
|
|
@@ -122,6 +124,7 @@ export async function request2(ctx, next) {
|
|
|
122
124
|
req.on('error', noop)
|
|
123
125
|
res.on('error', noop)
|
|
124
126
|
|
|
127
|
+
pendingSet.add(ctx)
|
|
125
128
|
try {
|
|
126
129
|
if (req.method === 'GET' || req.method === 'HEAD') {
|
|
127
130
|
req.resume() // Dump the body if there is one.
|
|
@@ -221,6 +224,8 @@ export async function request2(ctx, next) {
|
|
|
221
224
|
}
|
|
222
225
|
}
|
|
223
226
|
} finally {
|
|
227
|
+
pendingSet.delete(ctx)
|
|
228
|
+
|
|
224
229
|
if (!res.writableEnded) {
|
|
225
230
|
res.destroy()
|
|
226
231
|
logger.debug('request destroyed')
|
|
@@ -235,6 +240,8 @@ export async function request(ctx, next) {
|
|
|
235
240
|
const ac = ctx.signal !== undefined ? null : new AbortController()
|
|
236
241
|
|
|
237
242
|
let reqLogger = logger
|
|
243
|
+
|
|
244
|
+
pendingSet.add(ctx)
|
|
238
245
|
try {
|
|
239
246
|
ctx.url = requestTarget(req)
|
|
240
247
|
if (!ctx.url) {
|
|
@@ -346,6 +353,8 @@ export async function request(ctx, next) {
|
|
|
346
353
|
}
|
|
347
354
|
}
|
|
348
355
|
} finally {
|
|
356
|
+
pendingSet.delete(ctx)
|
|
357
|
+
|
|
349
358
|
if (!res.writableEnded) {
|
|
350
359
|
res.destroy()
|
|
351
360
|
logger.debug('request destroyed')
|