@nxtedition/nxt-undici 1.0.2 → 1.0.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/lib/index.js +1 -1
- package/lib/interceptor/log.js +14 -2
- package/package.json +1 -1
package/lib/index.js
CHANGED
package/lib/interceptor/log.js
CHANGED
|
@@ -1,11 +1,23 @@
|
|
|
1
1
|
const { parseHeaders } = require('../utils')
|
|
2
|
-
const xuid = require('xuid')
|
|
3
2
|
const { performance } = require('perf_hooks')
|
|
4
3
|
|
|
4
|
+
// https://github.com/fastify/fastify/blob/main/lib/reqIdGenFactory.js
|
|
5
|
+
// 2,147,483,647 (2^31 − 1) stands for max SMI value (an internal optimization of V8).
|
|
6
|
+
// With this upper bound, if you'll be generating 1k ids/sec, you're going to hit it in ~25 days.
|
|
7
|
+
// This is very likely to happen in real-world applications, hence the limit is enforced.
|
|
8
|
+
// Growing beyond this value will make the id generation slower and cause a deopt.
|
|
9
|
+
// In the worst cases, it will become a float, losing accuracy.
|
|
10
|
+
const maxInt = 2147483647
|
|
11
|
+
let nextReqId = Math.floor(Math.random() * maxInt)
|
|
12
|
+
function genReqId() {
|
|
13
|
+
nextReqId = (nextReqId + 1) & maxInt
|
|
14
|
+
return `req-${nextReqId.toString(36)}`
|
|
15
|
+
}
|
|
16
|
+
|
|
5
17
|
class Handler {
|
|
6
18
|
constructor(opts, { handler }) {
|
|
7
19
|
this.handler = handler
|
|
8
|
-
this.opts = opts.id ? opts : { ...opts, id:
|
|
20
|
+
this.opts = opts.id ? opts : { ...opts, id: genReqId() }
|
|
9
21
|
this.abort = null
|
|
10
22
|
this.aborted = false
|
|
11
23
|
this.logger = opts.logger.child({ ureq: { id: opts.id } })
|