@nxtedition/lib 21.4.1 → 21.4.2
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 +13 -3
- package/package.json +1 -1
package/http.js
CHANGED
|
@@ -35,6 +35,7 @@ function onTimeout() {
|
|
|
35
35
|
|
|
36
36
|
export class Context {
|
|
37
37
|
#id
|
|
38
|
+
#userAgent
|
|
38
39
|
#req
|
|
39
40
|
#res
|
|
40
41
|
#ac
|
|
@@ -47,16 +48,21 @@ export class Context {
|
|
|
47
48
|
assert(res)
|
|
48
49
|
assert(logger)
|
|
49
50
|
|
|
50
|
-
this.#id = req.headers['request-id'] || genReqId()
|
|
51
|
+
this.#id = req.headers['request-id'] || req.headers['Request-Id'] || genReqId()
|
|
52
|
+
this.#id = req.headers['user-agent'] || req.headers['User-Agent'] || ''
|
|
51
53
|
this.#req = req
|
|
52
54
|
this.#res = res
|
|
53
|
-
this.#logger = logger.child({ reqId: this.#id, url: req.url })
|
|
55
|
+
this.#logger = logger.child({ reqId: this.#id, url: req.url, userAgent: this.#userAgent })
|
|
54
56
|
}
|
|
55
57
|
|
|
56
58
|
get id() {
|
|
57
59
|
return this.#id
|
|
58
60
|
}
|
|
59
61
|
|
|
62
|
+
get userAgent() {
|
|
63
|
+
return this.#userAgent
|
|
64
|
+
}
|
|
65
|
+
|
|
60
66
|
get [kAbortController]() {
|
|
61
67
|
return this.#ac
|
|
62
68
|
}
|
|
@@ -229,9 +235,13 @@ export async function request(ctx, next) {
|
|
|
229
235
|
}
|
|
230
236
|
|
|
231
237
|
ctx.id = req.id = res.id = req.headers['request-id'] || genReqId()
|
|
238
|
+
ctx.userAgent = req['user-agent'] || req['User-Agent'] || ''
|
|
232
239
|
ctx.method = req.method
|
|
233
240
|
ctx.query = ctx.url.search.length > 1 ? querystring.parse(ctx.url.search.slice(1)) : {}
|
|
234
|
-
ctx.logger =
|
|
241
|
+
ctx.logger =
|
|
242
|
+
req.log =
|
|
243
|
+
res.log =
|
|
244
|
+
logger.child({ req: { id: req.id, url: req.url, userAgent: ctx.userAgent } })
|
|
235
245
|
|
|
236
246
|
if (ac) {
|
|
237
247
|
ctx.signal = ac.signal
|