@nxtedition/lib 26.3.2 → 26.3.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 +14 -36
- package/package.json +3 -3
package/http.js
CHANGED
|
@@ -13,8 +13,6 @@ export const kAbortController = Symbol('abortController')
|
|
|
13
13
|
const ERR_HEADER_EXPR =
|
|
14
14
|
/^(content-length|content-type|te|host|upgrade|trailers|connection|keep-alive|http2-settings|transfer-encoding|proxy-connection|proxy-authenticate|proxy-authorization)$/i
|
|
15
15
|
|
|
16
|
-
const pending = (globalThis._nxt_lib_http_pending = new Set())
|
|
17
|
-
|
|
18
16
|
// https://github.com/fastify/fastify/blob/main/lib/reqIdGenFactory.js
|
|
19
17
|
// 2,147,483,647 (2^31 − 1) stands for max SMI value (an internal optimization of V8).
|
|
20
18
|
// With this upper bound, if you'll be generating 1k ids/sec, you're going to hit it in ~25 days.
|
|
@@ -147,7 +145,6 @@ export async function upgradeMiddleware(ctx, next) {
|
|
|
147
145
|
})
|
|
148
146
|
|
|
149
147
|
const reqLogger = ctx.logger?.child({ req })
|
|
150
|
-
pending.add(ctx)
|
|
151
148
|
try {
|
|
152
149
|
const isHealthcheck = req.url === '/healthcheck' || req.url === '/_up'
|
|
153
150
|
if (!isHealthcheck) {
|
|
@@ -194,7 +191,6 @@ export async function upgradeMiddleware(ctx, next) {
|
|
|
194
191
|
}
|
|
195
192
|
socket.destroy(err)
|
|
196
193
|
} finally {
|
|
197
|
-
pending.delete(ctx)
|
|
198
194
|
if (!socket.writableEnded && !socket.destroyed) {
|
|
199
195
|
socket.destroy()
|
|
200
196
|
reqLogger?.warn('socket destroyed')
|
|
@@ -207,7 +203,6 @@ export async function requestMiddleware(ctx, next) {
|
|
|
207
203
|
const startTime = performance.now()
|
|
208
204
|
|
|
209
205
|
const reqLogger = ctx.logger?.child({ req })
|
|
210
|
-
pending.add(ctx)
|
|
211
206
|
try {
|
|
212
207
|
const isHealthcheck = req.url === '/healthcheck' || req.url === '/_up'
|
|
213
208
|
if (!isHealthcheck) {
|
|
@@ -240,14 +235,6 @@ export async function requestMiddleware(ctx, next) {
|
|
|
240
235
|
|
|
241
236
|
const thenable = next()
|
|
242
237
|
|
|
243
|
-
if (!req.destroyed || req.errored) {
|
|
244
|
-
req.on('error', noop)
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
if (!res.destroyed || res.errored) {
|
|
248
|
-
res.on('error', noop)
|
|
249
|
-
}
|
|
250
|
-
|
|
251
238
|
if (thenable?.then) {
|
|
252
239
|
await thenable
|
|
253
240
|
}
|
|
@@ -274,6 +261,18 @@ export async function requestMiddleware(ctx, next) {
|
|
|
274
261
|
} catch (err) {
|
|
275
262
|
ctx[kAbortController]?.abort(err)
|
|
276
263
|
|
|
264
|
+
if (!req.closed) {
|
|
265
|
+
req.on('error', (err) => {
|
|
266
|
+
reqLogger?.warn({ err }, 'request error')
|
|
267
|
+
})
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
if (!res.closed) {
|
|
271
|
+
res.on('error', (err) => {
|
|
272
|
+
reqLogger?.warn({ err }, 'response error')
|
|
273
|
+
})
|
|
274
|
+
}
|
|
275
|
+
|
|
277
276
|
const statusCode = err.statusCode || err.$metadata?.httpStatusCode || 500
|
|
278
277
|
const elapsedTime = performance.now() - startTime
|
|
279
278
|
|
|
@@ -339,7 +338,6 @@ export async function requestMiddleware(ctx, next) {
|
|
|
339
338
|
res.destroy(err)
|
|
340
339
|
}
|
|
341
340
|
} finally {
|
|
342
|
-
pending.delete(ctx)
|
|
343
341
|
if (res.writableEnded || res.destroyed || res.stream?.destroyed) {
|
|
344
342
|
// Do nothing..
|
|
345
343
|
} else {
|
|
@@ -394,7 +392,7 @@ export class IncomingMessage extends http.IncomingMessage {
|
|
|
394
392
|
export class ServerResponse extends http.ServerResponse {
|
|
395
393
|
#bytesWritten = 0
|
|
396
394
|
|
|
397
|
-
#created =
|
|
395
|
+
#created = performance.now()
|
|
398
396
|
#connect = -1
|
|
399
397
|
#headers = -1
|
|
400
398
|
#data = -1
|
|
@@ -426,15 +424,6 @@ export class ServerResponse extends http.ServerResponse {
|
|
|
426
424
|
return this.#bytesWritten
|
|
427
425
|
}
|
|
428
426
|
|
|
429
|
-
/**
|
|
430
|
-
* @param {http.IncomingMessage} req
|
|
431
|
-
*/
|
|
432
|
-
constructor(req) {
|
|
433
|
-
super(req)
|
|
434
|
-
|
|
435
|
-
this.#created = performance.now()
|
|
436
|
-
}
|
|
437
|
-
|
|
438
427
|
setHeaders() {
|
|
439
428
|
throw new Error('not supported')
|
|
440
429
|
}
|
|
@@ -634,7 +623,7 @@ export class Http2ServerRequest extends http2.Http2ServerRequest {
|
|
|
634
623
|
}
|
|
635
624
|
|
|
636
625
|
export class Http2ServerResponse extends http2.Http2ServerResponse {
|
|
637
|
-
#created =
|
|
626
|
+
#created = performance.now()
|
|
638
627
|
#bytesWritten = 0
|
|
639
628
|
#connect = -1
|
|
640
629
|
#headers = -1
|
|
@@ -654,13 +643,6 @@ export class Http2ServerResponse extends http2.Http2ServerResponse {
|
|
|
654
643
|
return this.#bytesWritten
|
|
655
644
|
}
|
|
656
645
|
|
|
657
|
-
constructor(req) {
|
|
658
|
-
super(req)
|
|
659
|
-
|
|
660
|
-
this.#created = performance.now()
|
|
661
|
-
this.#connect = 0
|
|
662
|
-
}
|
|
663
|
-
|
|
664
646
|
flushHeaders() {
|
|
665
647
|
if (!this.destroyed) {
|
|
666
648
|
if (this.#headers === -1) {
|
|
@@ -734,7 +716,6 @@ export async function request(ctx, next) {
|
|
|
734
716
|
|
|
735
717
|
let reqLogger = logger
|
|
736
718
|
|
|
737
|
-
pending.add(ctx)
|
|
738
719
|
try {
|
|
739
720
|
ctx.url = requestTarget(req)
|
|
740
721
|
if (!ctx.url) {
|
|
@@ -844,7 +825,6 @@ export async function request(ctx, next) {
|
|
|
844
825
|
}
|
|
845
826
|
}
|
|
846
827
|
} finally {
|
|
847
|
-
pending.delete(ctx)
|
|
848
828
|
if (!res.writableEnded) {
|
|
849
829
|
res.destroy()
|
|
850
830
|
logger.debug('request destroyed')
|
|
@@ -922,7 +902,6 @@ export async function upgrade(ctx, next) {
|
|
|
922
902
|
|
|
923
903
|
let aborted = false
|
|
924
904
|
let reqLogger = logger
|
|
925
|
-
pending.add(ctx)
|
|
926
905
|
try {
|
|
927
906
|
ctx.url = requestTarget(req)
|
|
928
907
|
if (!ctx.url) {
|
|
@@ -987,7 +966,6 @@ export async function upgrade(ctx, next) {
|
|
|
987
966
|
|
|
988
967
|
socket.destroy(err)
|
|
989
968
|
} finally {
|
|
990
|
-
pending.delete(ctx)
|
|
991
969
|
queueMicrotask(() => ac.abort())
|
|
992
970
|
}
|
|
993
971
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/lib",
|
|
3
|
-
"version": "26.3.
|
|
3
|
+
"version": "26.3.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Robert Nagy <robert.nagy@boffins.se>",
|
|
6
6
|
"type": "module",
|
|
@@ -79,7 +79,7 @@
|
|
|
79
79
|
"http-errors": "^2.0.0",
|
|
80
80
|
"json5": "^2.2.3",
|
|
81
81
|
"lodash": "^4.17.21",
|
|
82
|
-
"lru-cache": "^11.2.
|
|
82
|
+
"lru-cache": "^11.2.2",
|
|
83
83
|
"mime": "^4.0.7",
|
|
84
84
|
"mitata": "^1.0.34",
|
|
85
85
|
"moment-timezone": "^0.5.48",
|
|
@@ -108,7 +108,7 @@
|
|
|
108
108
|
"eslint-plugin-node": "^11.1.0",
|
|
109
109
|
"eslint-plugin-promise": "^7.2.1",
|
|
110
110
|
"husky": "^9.1.7",
|
|
111
|
-
"lint-staged": "^16.2.
|
|
111
|
+
"lint-staged": "^16.2.1",
|
|
112
112
|
"prettier": "^3.6.2",
|
|
113
113
|
"rxjs": "^7.8.2",
|
|
114
114
|
"typescript": "^5.9.2",
|