@nxtedition/lib 26.0.2 → 26.0.4
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 +27 -16
- package/package.json +1 -1
package/http.js
CHANGED
|
@@ -157,7 +157,7 @@ export async function upgradeMiddleware(ctx, next) {
|
|
|
157
157
|
try {
|
|
158
158
|
const isHealthcheck = req.url === '/healthcheck' || req.url === '/_up'
|
|
159
159
|
if (!isHealthcheck) {
|
|
160
|
-
ctx.logger?.debug({ req }, '
|
|
160
|
+
ctx.logger?.debug({ req }, 'request started')
|
|
161
161
|
}
|
|
162
162
|
|
|
163
163
|
const thenable = next()
|
|
@@ -219,10 +219,29 @@ export async function requestMiddleware(ctx, next) {
|
|
|
219
219
|
res.setHeader('request-id', ctx.id)
|
|
220
220
|
}
|
|
221
221
|
|
|
222
|
+
if (req.httpVersionMajor === 1 && (req.method === 'HEAD' || req.method === 'GET')) {
|
|
223
|
+
// Fast dump where request "has" already emitted all lifecycle events.
|
|
224
|
+
// This avoid a lot of unnecessary overhead otherwise introduced by
|
|
225
|
+
// stream.Readable life cycle rules. The downside is that this will
|
|
226
|
+
// break some servers that read GET bodies.
|
|
227
|
+
|
|
228
|
+
req._dumped = true
|
|
229
|
+
req._readableState.ended = true
|
|
230
|
+
req._readableState.endEmitted = true
|
|
231
|
+
req._readableState.destroyed = true
|
|
232
|
+
req._readableState.closed = true
|
|
233
|
+
req._readableState.closeEmitted = true
|
|
234
|
+
|
|
235
|
+
req._read()
|
|
236
|
+
}
|
|
237
|
+
|
|
222
238
|
const thenable = next()
|
|
223
239
|
|
|
224
|
-
if (
|
|
240
|
+
if (!req.destroyed || req.errored) {
|
|
225
241
|
req.on('error', noop)
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if (!res.destroyed || res.errored) {
|
|
226
245
|
res.on('error', noop)
|
|
227
246
|
}
|
|
228
247
|
|
|
@@ -230,7 +249,9 @@ export async function requestMiddleware(ctx, next) {
|
|
|
230
249
|
await thenable
|
|
231
250
|
}
|
|
232
251
|
|
|
233
|
-
|
|
252
|
+
if (!res.destroyed || !res.writableEnded) {
|
|
253
|
+
throw new Error('Response not completed')
|
|
254
|
+
}
|
|
234
255
|
|
|
235
256
|
const elapsedTime = performance.now() - startTime
|
|
236
257
|
|
|
@@ -319,7 +340,7 @@ export async function requestMiddleware(ctx, next) {
|
|
|
319
340
|
// Do nothing..
|
|
320
341
|
} else {
|
|
321
342
|
res.destroy()
|
|
322
|
-
ctx.logger?.warn(
|
|
343
|
+
ctx.logger?.warn('request destroyed')
|
|
323
344
|
}
|
|
324
345
|
}
|
|
325
346
|
}
|
|
@@ -334,13 +355,8 @@ export class IncomingMessage extends http.IncomingMessage {
|
|
|
334
355
|
#search
|
|
335
356
|
#query
|
|
336
357
|
|
|
337
|
-
constructor(...args) {
|
|
338
|
-
super(...args)
|
|
339
|
-
this.#id = this.headers['request-id'] || this.headers['Request-Id'] || genReqId()
|
|
340
|
-
}
|
|
341
|
-
|
|
342
358
|
get id() {
|
|
343
|
-
return this.#id
|
|
359
|
+
return (this.#id ??= this.headers['request-id'] || this.headers['Request-Id'] || genReqId())
|
|
344
360
|
}
|
|
345
361
|
|
|
346
362
|
get target() {
|
|
@@ -581,13 +597,8 @@ export class Http2ServerRequest extends http2.Http2ServerRequest {
|
|
|
581
597
|
#search
|
|
582
598
|
#query
|
|
583
599
|
|
|
584
|
-
constructor(...args) {
|
|
585
|
-
super(...args)
|
|
586
|
-
this.#id = this.headers['request-id'] || this.headers['Request-Id'] || genReqId()
|
|
587
|
-
}
|
|
588
|
-
|
|
589
600
|
get id() {
|
|
590
|
-
return this.#id
|
|
601
|
+
return (this.#id ??= this.headers['request-id'] || this.headers['Request-Id'] || genReqId())
|
|
591
602
|
}
|
|
592
603
|
|
|
593
604
|
get target() {
|