@nxtedition/nxt-undici 5.1.2 → 5.1.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/lib/index.js +2 -4
- package/lib/interceptor/log.js +13 -13
- package/lib/request.js +1 -2
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -72,13 +72,11 @@ function wrapDispatch(dispatcher) {
|
|
|
72
72
|
headers['user-agent'] = userAgent
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
const url = opts.url ? new URL(opts.url) : null
|
|
76
|
-
|
|
77
75
|
return dispatch(
|
|
78
76
|
{
|
|
79
77
|
id: opts.id,
|
|
80
|
-
origin: opts.origin
|
|
81
|
-
path: opts.path
|
|
78
|
+
origin: opts.origin,
|
|
79
|
+
path: opts.path,
|
|
82
80
|
method: opts.method ?? (opts.body ? 'POST' : 'GET'),
|
|
83
81
|
body: opts.body,
|
|
84
82
|
query: opts.query,
|
package/lib/interceptor/log.js
CHANGED
|
@@ -17,12 +17,15 @@ class Handler extends DecoratorHandler {
|
|
|
17
17
|
end: -1,
|
|
18
18
|
}
|
|
19
19
|
|
|
20
|
+
#statusCode
|
|
21
|
+
#headers
|
|
22
|
+
|
|
20
23
|
constructor(opts, { handler }) {
|
|
21
24
|
super(handler)
|
|
22
25
|
|
|
23
26
|
this.#handler = handler
|
|
24
27
|
this.#opts = opts
|
|
25
|
-
this.#logger = opts.logger
|
|
28
|
+
this.#logger = opts.logger.child({ ureq: opts })
|
|
26
29
|
|
|
27
30
|
this.#created = performance.now()
|
|
28
31
|
}
|
|
@@ -36,7 +39,6 @@ class Handler extends DecoratorHandler {
|
|
|
36
39
|
this.#timing.data = -1
|
|
37
40
|
this.#timing.end = -1
|
|
38
41
|
|
|
39
|
-
this.#logger = this.#logger.child({ ureq: this.#opts })
|
|
40
42
|
this.#logger.debug('upstream request started')
|
|
41
43
|
|
|
42
44
|
return this.#handler.onConnect((reason) => {
|
|
@@ -50,7 +52,6 @@ class Handler extends DecoratorHandler {
|
|
|
50
52
|
|
|
51
53
|
this.#logger.debug(
|
|
52
54
|
{
|
|
53
|
-
ureq: { id: this.#opts.id, url: String(this.#opts.url) },
|
|
54
55
|
ures: { statusCode, headers },
|
|
55
56
|
elapsedTime: this.#timing.headers,
|
|
56
57
|
},
|
|
@@ -67,14 +68,8 @@ class Handler extends DecoratorHandler {
|
|
|
67
68
|
onHeaders(statusCode, rawHeaders, resume, statusMessage, headers = parseHeaders(rawHeaders)) {
|
|
68
69
|
this.#timing.headers = performance.now() - this.#created
|
|
69
70
|
|
|
70
|
-
this.#
|
|
71
|
-
|
|
72
|
-
ureq: { id: this.#opts.id, url: String(this.#opts.url) },
|
|
73
|
-
ures: { statusCode, headers },
|
|
74
|
-
elapsedTime: this.#timing.headers,
|
|
75
|
-
},
|
|
76
|
-
'upstream request response',
|
|
77
|
-
)
|
|
71
|
+
this.#statusCode = statusCode
|
|
72
|
+
this.#headers = headers
|
|
78
73
|
|
|
79
74
|
return this.#handler.onHeaders(statusCode, null, resume, statusMessage, headers)
|
|
80
75
|
}
|
|
@@ -95,9 +90,11 @@ class Handler extends DecoratorHandler {
|
|
|
95
90
|
this.#logger.debug(
|
|
96
91
|
{
|
|
97
92
|
ures: {
|
|
93
|
+
statusCode: this.#statusCode,
|
|
94
|
+
headers: this.#headers,
|
|
95
|
+
timing: this.#timing,
|
|
98
96
|
bytesRead: this.#pos,
|
|
99
97
|
bytesReadPerSecond: (this.#pos * 1e3) / (this.#timing.end - this.#timing.data),
|
|
100
|
-
timing: this.#timing,
|
|
101
98
|
},
|
|
102
99
|
elapsedTime: this.#timing.end,
|
|
103
100
|
},
|
|
@@ -111,10 +108,13 @@ class Handler extends DecoratorHandler {
|
|
|
111
108
|
this.#timing.end = performance.now() - this.#created
|
|
112
109
|
|
|
113
110
|
const data = {
|
|
111
|
+
ureq: this.#opts,
|
|
114
112
|
ures: {
|
|
113
|
+
statusCode: this.#statusCode,
|
|
114
|
+
headers: this.#headers,
|
|
115
|
+
timing: this.#timing,
|
|
115
116
|
bytesRead: this.#pos,
|
|
116
117
|
bytesReadPerSecond: (this.#pos * 1e3) / (this.#timing.end - this.#timing.data),
|
|
117
|
-
timing: this.#timing,
|
|
118
118
|
},
|
|
119
119
|
elapsedTime: this.#timing.end,
|
|
120
120
|
err,
|
package/lib/request.js
CHANGED
|
@@ -158,7 +158,6 @@ export function request(dispatch, url, opts) {
|
|
|
158
158
|
}
|
|
159
159
|
|
|
160
160
|
let origin = url.origin
|
|
161
|
-
|
|
162
161
|
if (!origin) {
|
|
163
162
|
const protocol = url.protocol ?? 'http:'
|
|
164
163
|
const host = url.host ?? `${url.hostname}:${url.port ?? (protocol === 'https:' ? 443 : 80)}`
|
|
@@ -167,7 +166,7 @@ export function request(dispatch, url, opts) {
|
|
|
167
166
|
|
|
168
167
|
let path = url.path
|
|
169
168
|
if (!path) {
|
|
170
|
-
path = url.search ? `${url.pathname}${url.search}` : url
|
|
169
|
+
path = url.search ? `${url.pathname}${url.search}` : url.pathname
|
|
171
170
|
}
|
|
172
171
|
|
|
173
172
|
opts = { ...opts, origin, path }
|