@nxtedition/lib 23.17.7 → 23.17.8

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.
Files changed (2) hide show
  1. package/http.js +42 -40
  2. package/package.json +1 -1
package/http.js CHANGED
@@ -42,9 +42,6 @@ export class Context {
42
42
  #res
43
43
  #ac
44
44
  #logger
45
-
46
- // deprecated fields
47
- #userAgent
48
45
  #query
49
46
  #target
50
47
 
@@ -52,15 +49,14 @@ export class Context {
52
49
  assert(req)
53
50
  assert(res)
54
51
 
55
- this.#id = req.headers['request-id'] || req.headers['Request-Id'] || genReqId()
56
- this.#userAgent = req.headers['user-agent'] || req.headers['User-Agent'] || ''
52
+ this.#id = req.id || req.headers['request-id'] || req.headers['Request-Id'] || genReqId()
57
53
  this.#req = req
58
54
  this.#res = res
59
- this.#logger = logger.child({ rid: this.#id, userAgent: this.#userAgent })
55
+ this.#logger = logger.child({ rid: this.#id })
60
56
  }
61
57
 
62
58
  get id() {
63
- return this.#req.id ?? this.#id
59
+ return this.#id
64
60
  }
65
61
 
66
62
  get logger() {
@@ -75,6 +71,38 @@ export class Context {
75
71
  return this.#res
76
72
  }
77
73
 
74
+ get target() {
75
+ if (this.#req.target) {
76
+ return this.#req.target
77
+ }
78
+
79
+ this.#target ??= requestTarget(this.#req)
80
+
81
+ if (!this.#target) {
82
+ throw new createError.BadRequest('invalid url')
83
+ }
84
+
85
+ return this.#target
86
+ }
87
+
88
+ get query() {
89
+ if (this.#req.query) {
90
+ return this.#req.query
91
+ }
92
+
93
+ this.#target ??= requestTarget(this.#req)
94
+ this.#query ??=
95
+ this.#target.search.length > 1
96
+ ? Object.freeze(querystring.parse(this.#target.search.slice(1)))
97
+ : {}
98
+
99
+ return this.#query
100
+ }
101
+
102
+ get userAgent() {
103
+ return this.#req.headers['user-agent'] || this.#req.headers['User-Agent'] || ''
104
+ }
105
+
78
106
  get [kAbortController]() {
79
107
  return this.#ac
80
108
  }
@@ -84,11 +112,6 @@ export class Context {
84
112
  return this.#ac.signal
85
113
  }
86
114
 
87
- /** @deprecated */
88
- get userAgent() {
89
- return this.#req.userAgent ?? this.#userAgent
90
- }
91
-
92
115
  /** @deprecated */
93
116
  get method() {
94
117
  return this.#req.method
@@ -96,17 +119,7 @@ export class Context {
96
119
 
97
120
  /** @deprecated */
98
121
  get url() {
99
- if (this.#req.target) {
100
- return this.#req.target
101
- }
102
-
103
- this.#target ??= requestTarget(this.#req)
104
-
105
- if (!this.#target) {
106
- throw new createError.BadRequest('invalid url')
107
- }
108
-
109
- return this.#target
122
+ return this.target
110
123
  }
111
124
 
112
125
  /** @deprecated */
@@ -120,21 +133,6 @@ export class Context {
120
133
  this.#query = undefined
121
134
  }
122
135
 
123
- /** @deprecated */
124
- get query() {
125
- if (this.#req.query) {
126
- return this.#req.query
127
- }
128
-
129
- this.#target ??= requestTarget(this.#req)
130
- this.#query ??=
131
- this.#target.search.length > 1
132
- ? Object.freeze(querystring.parse(this.#target.search.slice(1)))
133
- : {}
134
-
135
- return this.#query
136
- }
137
-
138
136
  /** @deprecated */
139
137
  set logger(logger) {
140
138
  this.#logger = logger.child({ rid: this.#id })
@@ -349,15 +347,17 @@ export class IncomingMessage extends http.IncomingMessage {
349
347
  #socket
350
348
  #target
351
349
 
350
+ #id
352
351
  #search
353
352
  #query
354
353
 
355
354
  constructor(...args) {
356
355
  super(...args)
356
+ this.#id = this.headers['request-id'] || this.headers['Request-Id'] || genReqId()
357
357
  }
358
358
 
359
359
  get id() {
360
- return this.headers['request-id'] || this.headers['Request-Id']
360
+ return this.#id
361
361
  }
362
362
 
363
363
  get target() {
@@ -493,15 +493,17 @@ export class Http2ServerRequest extends http2.Http2ServerRequest {
493
493
  #socket
494
494
  #target
495
495
 
496
+ #id
496
497
  #search
497
498
  #query
498
499
 
499
500
  constructor(...args) {
500
501
  super(...args)
502
+ this.#id = this.headers['request-id'] || this.headers['Request-Id'] || genReqId()
501
503
  }
502
504
 
503
505
  get id() {
504
- return this.headers['request-id'] || this.headers['Request-Id']
506
+ return this.#id
505
507
  }
506
508
 
507
509
  get target() {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "23.17.7",
3
+ "version": "23.17.8",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "type": "module",