@nxtedition/nxt-undici 2.0.3 → 2.0.5
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
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
|
-
abort: (await import('./interceptor/abort.js')).default,
|
|
133
132
|
catch: (await import('./interceptor/catch.js')).default,
|
|
134
133
|
responseContent: (await import('./interceptor/response-content.js')).default,
|
|
135
134
|
requestContent: (await import('./interceptor/request-content.js')).default,
|
|
@@ -227,8 +226,8 @@ export async function request(url, opts) {
|
|
|
227
226
|
dispatch = dispatchers.catch(dispatch)
|
|
228
227
|
dispatch = dispatchers.requestBodyFactory(dispatch)
|
|
229
228
|
dispatch = dispatchers.abort(dispatch)
|
|
230
|
-
dispatch = dispatchers.requestId(dispatch)
|
|
231
229
|
dispatch = dispatchers.log(dispatch)
|
|
230
|
+
dispatch = dispatchers.requestId(dispatch)
|
|
232
231
|
dispatch = dispatchers.responseRetry(dispatch)
|
|
233
232
|
dispatch = dispatchers.responseStatusRetry(dispatch)
|
|
234
233
|
dispatch = dispatchers.responseBodyRetry(dispatch)
|
|
@@ -329,7 +328,9 @@ export async function request(url, opts) {
|
|
|
329
328
|
),
|
|
330
329
|
)
|
|
331
330
|
|
|
332
|
-
if (
|
|
331
|
+
if (method === 'HEAD') {
|
|
332
|
+
await res.dump()
|
|
333
|
+
} else if (res.statusCode >= 400) {
|
|
333
334
|
// TODO (fix): Limit the size of the body?
|
|
334
335
|
const data =
|
|
335
336
|
res.headers['content-type']?.toLowerCase() === 'application/json'
|
package/lib/interceptor/log.js
CHANGED
|
@@ -7,7 +7,7 @@ class Handler {
|
|
|
7
7
|
this.opts = opts
|
|
8
8
|
this.abort = null
|
|
9
9
|
this.aborted = false
|
|
10
|
-
this.logger = opts.logger.child({ ureq: opts })
|
|
10
|
+
this.logger = opts.logger.child({ ureq: { id: opts.id } })
|
|
11
11
|
this.pos = 0
|
|
12
12
|
this.stats = {
|
|
13
13
|
start: -1,
|
|
@@ -23,7 +23,7 @@ class Handler {
|
|
|
23
23
|
onConnect(abort) {
|
|
24
24
|
this.abort = abort
|
|
25
25
|
this.stats.start = performance.now()
|
|
26
|
-
this.logger.debug('upstream request started')
|
|
26
|
+
this.logger.debug({ ureq: this.opts }, 'upstream request started')
|
|
27
27
|
this.handler.onConnect((reason) => {
|
|
28
28
|
this.aborted = true
|
|
29
29
|
this.abort(reason)
|
|
@@ -99,6 +99,7 @@ class Handler {
|
|
|
99
99
|
'upstream request failed',
|
|
100
100
|
)
|
|
101
101
|
}
|
|
102
|
+
|
|
102
103
|
return this.handler.onError(err)
|
|
103
104
|
}
|
|
104
105
|
}
|
|
@@ -7,9 +7,11 @@ class Handler {
|
|
|
7
7
|
this.length = length
|
|
8
8
|
this.hasher = this.md5 ? crypto.createHash('md5') : null
|
|
9
9
|
this.pos = 0
|
|
10
|
+
this.abort = null
|
|
10
11
|
}
|
|
11
12
|
|
|
12
13
|
onConnect(abort) {
|
|
14
|
+
this.abort = abort
|
|
13
15
|
return this.handler.onConnect(abort)
|
|
14
16
|
}
|
|
15
17
|
|
|
@@ -25,22 +27,25 @@ class Handler {
|
|
|
25
27
|
|
|
26
28
|
onRequestSent() {
|
|
27
29
|
const hash = this.hasher?.digest('base64')
|
|
30
|
+
|
|
28
31
|
if (this.md5 != null && hash !== this.md5) {
|
|
29
|
-
this.
|
|
32
|
+
this.abort(
|
|
30
33
|
Object.assign(new Error('Request Content-Length mismatch'), {
|
|
31
34
|
expected: this.md5,
|
|
32
35
|
actual: hash,
|
|
33
36
|
}),
|
|
34
37
|
)
|
|
35
38
|
}
|
|
39
|
+
|
|
36
40
|
if (this.length != null && this.pos !== Number(this.length)) {
|
|
37
|
-
|
|
41
|
+
this.abort(
|
|
38
42
|
Object.assign(new Error('Request Content-Length mismatch'), {
|
|
39
43
|
expected: Number(this.length),
|
|
40
44
|
actual: this.pos,
|
|
41
45
|
}),
|
|
42
46
|
)
|
|
43
47
|
}
|
|
48
|
+
|
|
44
49
|
return this.handler.onRequestSent()
|
|
45
50
|
}
|
|
46
51
|
|
|
@@ -41,14 +41,16 @@ class Handler {
|
|
|
41
41
|
|
|
42
42
|
onComplete(rawTrailers) {
|
|
43
43
|
const hash = this.hasher?.digest('base64')
|
|
44
|
+
|
|
44
45
|
if (this.md5 != null && hash !== this.md5) {
|
|
45
|
-
this.handler.onError(
|
|
46
|
+
return this.handler.onError(
|
|
46
47
|
Object.assign(new Error('Request Content-Length mismatch'), {
|
|
47
48
|
expected: this.md5,
|
|
48
49
|
actual: hash,
|
|
49
50
|
}),
|
|
50
51
|
)
|
|
51
52
|
}
|
|
53
|
+
|
|
52
54
|
if (this.length != null && this.pos !== Number(this.length)) {
|
|
53
55
|
return this.handler.onError(
|
|
54
56
|
Object.assign(new Error('Request Content-Length mismatch'), {
|
|
@@ -57,6 +59,7 @@ class Handler {
|
|
|
57
59
|
}),
|
|
58
60
|
)
|
|
59
61
|
}
|
|
62
|
+
|
|
60
63
|
return this.handler.onComplete(rawTrailers)
|
|
61
64
|
}
|
|
62
65
|
|
package/package.json
CHANGED
package/lib/interceptor/abort.js
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { AbortError } from '../utils.js'
|
|
2
|
-
|
|
3
|
-
class Handler {
|
|
4
|
-
constructor(opts, { handler }) {
|
|
5
|
-
this.opts = opts
|
|
6
|
-
this.handler = handler
|
|
7
|
-
this.pos = 0
|
|
8
|
-
this.reason = null
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
onConnect(abort) {
|
|
12
|
-
this.abort = abort
|
|
13
|
-
this.handler.onConnect((reason) => {
|
|
14
|
-
this.reason = reason ?? new AbortError()
|
|
15
|
-
})
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
onBodySent(chunk) {
|
|
19
|
-
return this.handler.onBodySent(chunk)
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
onRequestSent() {
|
|
23
|
-
return this.handler.onRequestSent()
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
onUpgrade(statusCode, rawHeaders, socket) {
|
|
27
|
-
return this.handler.onUpgrade(statusCode, rawHeaders, socket)
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
onHeaders(statusCode, rawHeaders, resume, statusMessage) {
|
|
31
|
-
if (this.reason == null) {
|
|
32
|
-
const ret = this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage)
|
|
33
|
-
if (this.reason == null) {
|
|
34
|
-
return ret
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return true
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
onData(chunk) {
|
|
42
|
-
if (this.reason == null) {
|
|
43
|
-
const ret = this.handler.onData(chunk)
|
|
44
|
-
if (this.reason == null) {
|
|
45
|
-
return ret
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
this.pos += chunk.length
|
|
50
|
-
if (this.pos < 128 * 1024) {
|
|
51
|
-
return true
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
this.abort(this.reason)
|
|
55
|
-
|
|
56
|
-
return false
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
onComplete(rawTrailers) {
|
|
60
|
-
return this.onFinally(this.reason, rawTrailers)
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
onError(err) {
|
|
64
|
-
return this.onFinally(err)
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
onFinally(err, rawTrailers) {
|
|
68
|
-
return err == null ? this.handler.onComplete(rawTrailers) : this.handler.onError(err)
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
export default (dispatch) => (opts, handler) => dispatch(opts, new Handler(opts, { handler }))
|