@nxtedition/nxt-undici 2.0.7 → 2.0.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.
- package/lib/index.js +0 -3
- package/lib/interceptor/log.js +6 -1
- package/lib/interceptor/redirect.js +12 -9
- package/lib/interceptor/request-content.js +3 -1
- package/lib/interceptor/response-content.js +2 -0
- package/lib/interceptor/signal.js +5 -4
- package/package.json +1 -1
- package/lib/interceptor/catch.js +0 -71
package/lib/index.js
CHANGED
|
@@ -129,7 +129,6 @@ class Readable extends stream.Readable {
|
|
|
129
129
|
const dispatchers = {
|
|
130
130
|
requestBody: (await import('./interceptor/request-body.js')).default,
|
|
131
131
|
requestBodyFactory: (await import('./interceptor/request-body-factory.js')).default,
|
|
132
|
-
catch: (await import('./interceptor/catch.js')).default,
|
|
133
132
|
responseContent: (await import('./interceptor/response-content.js')).default,
|
|
134
133
|
requestContent: (await import('./interceptor/request-content.js')).default,
|
|
135
134
|
log: (await import('./interceptor/log.js')).default,
|
|
@@ -223,7 +222,6 @@ export async function request(url, opts) {
|
|
|
223
222
|
let dispatch = dispatcherCache.get(dispatcher)
|
|
224
223
|
if (dispatch == null) {
|
|
225
224
|
dispatch = (opts, handler) => dispatcher.dispatch(opts, handler)
|
|
226
|
-
dispatch = dispatchers.catch(dispatch)
|
|
227
225
|
dispatch = dispatchers.requestBodyFactory(dispatch)
|
|
228
226
|
dispatch = dispatchers.log(dispatch)
|
|
229
227
|
dispatch = dispatchers.requestId(dispatch)
|
|
@@ -250,7 +248,6 @@ export async function request(url, opts) {
|
|
|
250
248
|
headers,
|
|
251
249
|
origin: url.origin,
|
|
252
250
|
path: url.path ?? (url.search ? `${url.pathname}${url.search ?? ''}` : url.pathname),
|
|
253
|
-
query: opts.query,
|
|
254
251
|
reset: opts.reset ?? false,
|
|
255
252
|
blocking: opts.blocking ?? false,
|
|
256
253
|
headersTimeout: opts.headersTimeout,
|
package/lib/interceptor/log.js
CHANGED
|
@@ -24,7 +24,8 @@ class Handler {
|
|
|
24
24
|
this.abort = abort
|
|
25
25
|
this.stats.start = performance.now()
|
|
26
26
|
this.logger.debug({ ureq: this.opts }, 'upstream request started')
|
|
27
|
-
|
|
27
|
+
|
|
28
|
+
return this.handler.onConnect((reason) => {
|
|
28
29
|
this.aborted = true
|
|
29
30
|
this.abort(reason)
|
|
30
31
|
})
|
|
@@ -35,6 +36,7 @@ class Handler {
|
|
|
35
36
|
socket.on('close', () => {
|
|
36
37
|
this.logger.debug('upstream request socket closed')
|
|
37
38
|
})
|
|
39
|
+
|
|
38
40
|
return this.handler.onUpgrade(statusCode, rawHeaders, socket)
|
|
39
41
|
}
|
|
40
42
|
|
|
@@ -62,6 +64,7 @@ class Handler {
|
|
|
62
64
|
},
|
|
63
65
|
'upstream request response',
|
|
64
66
|
)
|
|
67
|
+
|
|
65
68
|
return this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage)
|
|
66
69
|
}
|
|
67
70
|
|
|
@@ -71,6 +74,7 @@ class Handler {
|
|
|
71
74
|
}
|
|
72
75
|
|
|
73
76
|
this.pos += chunk.length
|
|
77
|
+
|
|
74
78
|
return this.handler.onData(chunk)
|
|
75
79
|
}
|
|
76
80
|
|
|
@@ -82,6 +86,7 @@ class Handler {
|
|
|
82
86
|
{ bytesRead: this.pos, elapsedTime: this.stats.end, stats: this.stats },
|
|
83
87
|
'upstream request completed',
|
|
84
88
|
)
|
|
89
|
+
|
|
85
90
|
return this.handler.onComplete(rawTrailers)
|
|
86
91
|
}
|
|
87
92
|
|
|
@@ -46,10 +46,6 @@ class Handler {
|
|
|
46
46
|
return this.handler.onRequestSent()
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
onError(error) {
|
|
50
|
-
return this.handler.onError(error)
|
|
51
|
-
}
|
|
52
|
-
|
|
53
49
|
onHeaders(statusCode, headers, resume, statusText) {
|
|
54
50
|
if (redirectableStatusCodes.indexOf(statusCode) === -1) {
|
|
55
51
|
return this.handler.onHeaders(statusCode, headers, resume, statusText)
|
|
@@ -92,9 +88,12 @@ class Handler {
|
|
|
92
88
|
statusCode === 303,
|
|
93
89
|
this.opts.origin !== origin,
|
|
94
90
|
),
|
|
91
|
+
follow: {
|
|
92
|
+
...this.opts.follow,
|
|
93
|
+
count: this.maxCount - 1,
|
|
94
|
+
},
|
|
95
95
|
path,
|
|
96
96
|
origin,
|
|
97
|
-
query: null,
|
|
98
97
|
}
|
|
99
98
|
|
|
100
99
|
// https://tools.ietf.org/html/rfc7231#section-6.4.4
|
|
@@ -138,14 +137,18 @@ class Handler {
|
|
|
138
137
|
|
|
139
138
|
See comment on onData method above for more detailed informations.
|
|
140
139
|
*/
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
140
|
+
this.dispatch(
|
|
141
|
+
this.opts,
|
|
142
|
+
new Handler(this.opts, { handler: this.handler, dispatch: this.dispatch }),
|
|
143
|
+
)
|
|
145
144
|
} else {
|
|
146
145
|
return this.handler.onComplete(trailers)
|
|
147
146
|
}
|
|
148
147
|
}
|
|
148
|
+
|
|
149
|
+
onError(error) {
|
|
150
|
+
return this.handler.onError(error)
|
|
151
|
+
}
|
|
149
152
|
}
|
|
150
153
|
|
|
151
154
|
// https://tools.ietf.org/html/rfc7231#section-6.4.4
|
|
@@ -12,6 +12,7 @@ class Handler {
|
|
|
12
12
|
|
|
13
13
|
onConnect(abort) {
|
|
14
14
|
this.abort = abort
|
|
15
|
+
|
|
15
16
|
return this.handler.onConnect(abort)
|
|
16
17
|
}
|
|
17
18
|
|
|
@@ -22,6 +23,7 @@ class Handler {
|
|
|
22
23
|
onBodySent(chunk) {
|
|
23
24
|
this.pos += chunk.length
|
|
24
25
|
this.hasher?.update(chunk)
|
|
26
|
+
|
|
25
27
|
return this.handler.onBodySent(chunk)
|
|
26
28
|
}
|
|
27
29
|
|
|
@@ -62,7 +64,7 @@ class Handler {
|
|
|
62
64
|
}
|
|
63
65
|
|
|
64
66
|
onError(err) {
|
|
65
|
-
this.handler.onError(err)
|
|
67
|
+
return this.handler.onError(err)
|
|
66
68
|
}
|
|
67
69
|
}
|
|
68
70
|
|
|
@@ -30,12 +30,14 @@ class Handler {
|
|
|
30
30
|
this.md5 = findHeader(rawHeaders, 'content-md5')
|
|
31
31
|
this.length = findHeader(rawHeaders, 'content-length')
|
|
32
32
|
this.hasher = this.md5 != null ? crypto.createHash('md5') : null
|
|
33
|
+
|
|
33
34
|
return this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage)
|
|
34
35
|
}
|
|
35
36
|
|
|
36
37
|
onData(chunk) {
|
|
37
38
|
this.pos += chunk.length
|
|
38
39
|
this.hasher?.update(chunk)
|
|
40
|
+
|
|
39
41
|
return this.handler.onData(chunk)
|
|
40
42
|
}
|
|
41
43
|
|
|
@@ -6,13 +6,12 @@ class Handler {
|
|
|
6
6
|
}
|
|
7
7
|
|
|
8
8
|
onConnect(abort) {
|
|
9
|
-
this.abort = () => abort(this.signal.reason)
|
|
10
|
-
|
|
11
|
-
this.signal.addEventListener('abort', this.abort)
|
|
12
|
-
|
|
13
9
|
if (this.signal.aborted) {
|
|
14
10
|
abort(this.signal.reason)
|
|
15
11
|
} else {
|
|
12
|
+
this.abort = () => abort(this.signal.reason)
|
|
13
|
+
this.signal.addEventListener('abort', this.abort)
|
|
14
|
+
|
|
16
15
|
this.handler.onConnect(abort)
|
|
17
16
|
}
|
|
18
17
|
}
|
|
@@ -41,6 +40,7 @@ class Handler {
|
|
|
41
40
|
if (this.abort) {
|
|
42
41
|
this.signal.removeEventListener('abort', this.abort)
|
|
43
42
|
}
|
|
43
|
+
|
|
44
44
|
return this.handler.onComplete(rawTrailers)
|
|
45
45
|
}
|
|
46
46
|
|
|
@@ -48,6 +48,7 @@ class Handler {
|
|
|
48
48
|
if (this.abort) {
|
|
49
49
|
this.signal.removeEventListener('abort', this.abort)
|
|
50
50
|
}
|
|
51
|
+
|
|
51
52
|
return this.handler.onError(err)
|
|
52
53
|
}
|
|
53
54
|
}
|
package/package.json
CHANGED
package/lib/interceptor/catch.js
DELETED
|
@@ -1,71 +0,0 @@
|
|
|
1
|
-
class Handler {
|
|
2
|
-
constructor(opts, { handler }) {
|
|
3
|
-
this.handler = handler
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
onConnect(abort) {
|
|
7
|
-
this.abort = abort
|
|
8
|
-
try {
|
|
9
|
-
return this.handler.onConnect(abort)
|
|
10
|
-
} catch (err) {
|
|
11
|
-
this.abort(err)
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
onUpgrade(statusCode, rawHeaders, socket) {
|
|
16
|
-
try {
|
|
17
|
-
return this.handler.onUpgrade(statusCode, rawHeaders, socket)
|
|
18
|
-
} catch (err) {
|
|
19
|
-
this.abort(err)
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
onBodySent(chunk) {
|
|
24
|
-
try {
|
|
25
|
-
return this.handler.onBodySent(chunk)
|
|
26
|
-
} catch (err) {
|
|
27
|
-
this.abort(err)
|
|
28
|
-
}
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
onRequestSent() {
|
|
32
|
-
try {
|
|
33
|
-
return this.handler.onRequestSent()
|
|
34
|
-
} catch (err) {
|
|
35
|
-
this.abort(err)
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
onHeaders(statusCode, rawHeaders, resume, statusMessage) {
|
|
40
|
-
try {
|
|
41
|
-
return this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage)
|
|
42
|
-
} catch (err) {
|
|
43
|
-
this.abort(err)
|
|
44
|
-
return false
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
onData(chunk) {
|
|
49
|
-
try {
|
|
50
|
-
return this.handler.onData(chunk)
|
|
51
|
-
} catch (err) {
|
|
52
|
-
this.abort(err)
|
|
53
|
-
return false
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
onComplete(rawTrailers) {
|
|
58
|
-
try {
|
|
59
|
-
return this.handler.onComplete(rawTrailers)
|
|
60
|
-
} catch (err) {
|
|
61
|
-
this.abort(err)
|
|
62
|
-
return false
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
onError(err) {
|
|
67
|
-
return this.handler.onError(err)
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
export default (dispatch) => (opts, handler) => dispatch(opts, new Handler(opts, { handler }))
|