@nxtedition/lib 25.1.3 → 25.1.6
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 +5 -23
- package/package.json +1 -1
package/http.js
CHANGED
|
@@ -140,8 +140,6 @@ export class Context {
|
|
|
140
140
|
|
|
141
141
|
function noop() {}
|
|
142
142
|
|
|
143
|
-
const pendingSet = (globalThis._nxt_lib_http_pending ??= new Set())
|
|
144
|
-
|
|
145
143
|
export async function upgradeMiddleware(ctx, next) {
|
|
146
144
|
const { req, socket } = ctx
|
|
147
145
|
const startTime = performance.now()
|
|
@@ -156,14 +154,8 @@ export async function upgradeMiddleware(ctx, next) {
|
|
|
156
154
|
}
|
|
157
155
|
})
|
|
158
156
|
|
|
159
|
-
const isHealthcheck = req.url === '/healthcheck' || req.url === '/_up'
|
|
160
|
-
|
|
161
|
-
pendingSet.add(ctx)
|
|
162
157
|
try {
|
|
163
|
-
|
|
164
|
-
req.resume() // Dump the body if there is one.
|
|
165
|
-
}
|
|
166
|
-
|
|
158
|
+
const isHealthcheck = req.url === '/healthcheck' || req.url === '/_up'
|
|
167
159
|
if (!isHealthcheck) {
|
|
168
160
|
ctx.logger?.debug({ req }, 'stream started')
|
|
169
161
|
}
|
|
@@ -206,8 +198,6 @@ export async function upgradeMiddleware(ctx, next) {
|
|
|
206
198
|
}
|
|
207
199
|
socket.destroy(err)
|
|
208
200
|
} finally {
|
|
209
|
-
pendingSet.delete(ctx)
|
|
210
|
-
|
|
211
201
|
if (!socket.writableEnded && !socket.destroyed) {
|
|
212
202
|
socket.destroy()
|
|
213
203
|
ctx.logger?.warn('socket destroyed')
|
|
@@ -219,14 +209,8 @@ export async function requestMiddleware(ctx, next) {
|
|
|
219
209
|
const { req, res } = ctx
|
|
220
210
|
const startTime = performance.now()
|
|
221
211
|
|
|
222
|
-
pendingSet.add(ctx)
|
|
223
212
|
try {
|
|
224
|
-
if (req.method === 'GET' || req.method === 'HEAD' || req.method === 'OPTIONS') {
|
|
225
|
-
req.resume() // Dump the body if there is one.
|
|
226
|
-
}
|
|
227
|
-
|
|
228
213
|
const isHealthcheck = req.url === '/healthcheck' || req.url === '/_up'
|
|
229
|
-
|
|
230
214
|
if (!isHealthcheck) {
|
|
231
215
|
ctx.logger?.debug({ req }, 'request started')
|
|
232
216
|
}
|
|
@@ -237,9 +221,12 @@ export async function requestMiddleware(ctx, next) {
|
|
|
237
221
|
|
|
238
222
|
const thenable = next()
|
|
239
223
|
|
|
240
|
-
if (thenable?.then) {
|
|
224
|
+
if (thenable?.then || res.errored || req.errored) {
|
|
241
225
|
req.on('error', noop)
|
|
242
226
|
res.on('error', noop)
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (thenable?.then) {
|
|
243
230
|
await thenable
|
|
244
231
|
}
|
|
245
232
|
|
|
@@ -328,8 +315,6 @@ export async function requestMiddleware(ctx, next) {
|
|
|
328
315
|
res.destroy(err)
|
|
329
316
|
}
|
|
330
317
|
} finally {
|
|
331
|
-
pendingSet.delete(ctx)
|
|
332
|
-
|
|
333
318
|
if (res.writableEnded || res.destroyed || res.stream?.destroyed) {
|
|
334
319
|
// Do nothing..
|
|
335
320
|
} else {
|
|
@@ -636,7 +621,6 @@ export async function request(ctx, next) {
|
|
|
636
621
|
|
|
637
622
|
let reqLogger = logger
|
|
638
623
|
|
|
639
|
-
pendingSet.add(ctx)
|
|
640
624
|
try {
|
|
641
625
|
ctx.url = requestTarget(req)
|
|
642
626
|
if (!ctx.url) {
|
|
@@ -746,8 +730,6 @@ export async function request(ctx, next) {
|
|
|
746
730
|
}
|
|
747
731
|
}
|
|
748
732
|
} finally {
|
|
749
|
-
pendingSet.delete(ctx)
|
|
750
|
-
|
|
751
733
|
if (!res.writableEnded) {
|
|
752
734
|
res.destroy()
|
|
753
735
|
logger.debug('request destroyed')
|