@nxtedition/lib 26.3.1 → 26.3.3
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 +2 -28
- package/package.json +3 -3
- package/util/template/index.test.js +13 -0
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) {
|
|
@@ -339,7 +334,6 @@ export async function requestMiddleware(ctx, next) {
|
|
|
339
334
|
res.destroy(err)
|
|
340
335
|
}
|
|
341
336
|
} finally {
|
|
342
|
-
pending.delete(ctx)
|
|
343
337
|
if (res.writableEnded || res.destroyed || res.stream?.destroyed) {
|
|
344
338
|
// Do nothing..
|
|
345
339
|
} else {
|
|
@@ -394,7 +388,7 @@ export class IncomingMessage extends http.IncomingMessage {
|
|
|
394
388
|
export class ServerResponse extends http.ServerResponse {
|
|
395
389
|
#bytesWritten = 0
|
|
396
390
|
|
|
397
|
-
#created =
|
|
391
|
+
#created = performance.now()
|
|
398
392
|
#connect = -1
|
|
399
393
|
#headers = -1
|
|
400
394
|
#data = -1
|
|
@@ -426,15 +420,6 @@ export class ServerResponse extends http.ServerResponse {
|
|
|
426
420
|
return this.#bytesWritten
|
|
427
421
|
}
|
|
428
422
|
|
|
429
|
-
/**
|
|
430
|
-
* @param {http.IncomingMessage} req
|
|
431
|
-
*/
|
|
432
|
-
constructor(req) {
|
|
433
|
-
super(req)
|
|
434
|
-
|
|
435
|
-
this.#created = performance.now()
|
|
436
|
-
}
|
|
437
|
-
|
|
438
423
|
setHeaders() {
|
|
439
424
|
throw new Error('not supported')
|
|
440
425
|
}
|
|
@@ -634,7 +619,7 @@ export class Http2ServerRequest extends http2.Http2ServerRequest {
|
|
|
634
619
|
}
|
|
635
620
|
|
|
636
621
|
export class Http2ServerResponse extends http2.Http2ServerResponse {
|
|
637
|
-
#created =
|
|
622
|
+
#created = performance.now()
|
|
638
623
|
#bytesWritten = 0
|
|
639
624
|
#connect = -1
|
|
640
625
|
#headers = -1
|
|
@@ -654,13 +639,6 @@ export class Http2ServerResponse extends http2.Http2ServerResponse {
|
|
|
654
639
|
return this.#bytesWritten
|
|
655
640
|
}
|
|
656
641
|
|
|
657
|
-
constructor(req) {
|
|
658
|
-
super(req)
|
|
659
|
-
|
|
660
|
-
this.#created = performance.now()
|
|
661
|
-
this.#connect = 0
|
|
662
|
-
}
|
|
663
|
-
|
|
664
642
|
flushHeaders() {
|
|
665
643
|
if (!this.destroyed) {
|
|
666
644
|
if (this.#headers === -1) {
|
|
@@ -734,7 +712,6 @@ export async function request(ctx, next) {
|
|
|
734
712
|
|
|
735
713
|
let reqLogger = logger
|
|
736
714
|
|
|
737
|
-
pending.add(ctx)
|
|
738
715
|
try {
|
|
739
716
|
ctx.url = requestTarget(req)
|
|
740
717
|
if (!ctx.url) {
|
|
@@ -844,7 +821,6 @@ export async function request(ctx, next) {
|
|
|
844
821
|
}
|
|
845
822
|
}
|
|
846
823
|
} finally {
|
|
847
|
-
pending.delete(ctx)
|
|
848
824
|
if (!res.writableEnded) {
|
|
849
825
|
res.destroy()
|
|
850
826
|
logger.debug('request destroyed')
|
|
@@ -922,7 +898,6 @@ export async function upgrade(ctx, next) {
|
|
|
922
898
|
|
|
923
899
|
let aborted = false
|
|
924
900
|
let reqLogger = logger
|
|
925
|
-
pending.add(ctx)
|
|
926
901
|
try {
|
|
927
902
|
ctx.url = requestTarget(req)
|
|
928
903
|
if (!ctx.url) {
|
|
@@ -987,7 +962,6 @@ export async function upgrade(ctx, next) {
|
|
|
987
962
|
|
|
988
963
|
socket.destroy(err)
|
|
989
964
|
} finally {
|
|
990
|
-
pending.delete(ctx)
|
|
991
965
|
queueMicrotask(() => ac.abort())
|
|
992
966
|
}
|
|
993
967
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nxtedition/lib",
|
|
3
|
-
"version": "26.3.
|
|
3
|
+
"version": "26.3.3",
|
|
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",
|
|
@@ -79,3 +79,16 @@ test('string concat', async (t) => {
|
|
|
79
79
|
'pre body post',
|
|
80
80
|
)
|
|
81
81
|
})
|
|
82
|
+
|
|
83
|
+
test('syntax error', async (t) => {
|
|
84
|
+
const { resolveTemplate } = makeTemplateCompiler({})
|
|
85
|
+
const x = '{{#js $.test + }}'
|
|
86
|
+
await assert.rejects(
|
|
87
|
+
async () => {
|
|
88
|
+
await resolveTemplate(x, { test: 1 })
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
name: 'Error',
|
|
92
|
+
},
|
|
93
|
+
)
|
|
94
|
+
})
|