@nxtedition/nxt-undici 2.0.12 → 2.0.14
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
|
@@ -1,61 +1,19 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
this.dispatch = dispatch
|
|
5
|
-
this.ac = new AbortController()
|
|
6
|
-
|
|
7
|
-
const signal = opts.signal ? AbortSignal.any([this.ac.signal, opts.signal]) : this.ac.signal
|
|
8
|
-
|
|
9
|
-
const body = opts.body({ signal })
|
|
10
|
-
|
|
11
|
-
if (typeof body.then === 'function') {
|
|
12
|
-
body.then(
|
|
13
|
-
(body) => this.dispatch({ ...opts, body }, handler),
|
|
14
|
-
(err) => this.handler.onError(err),
|
|
15
|
-
)
|
|
16
|
-
} else {
|
|
17
|
-
this.dispatch({ ...opts, body }, handler)
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
onConnect(abort) {
|
|
22
|
-
this.abort = (err) => {
|
|
23
|
-
this.ac.abort(err)
|
|
24
|
-
abort(err)
|
|
25
|
-
}
|
|
26
|
-
return this.handler.onConnect(abort)
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
onUpgrade(statusCode, rawHeaders, socket) {
|
|
30
|
-
return this.handler.onUpgrade(statusCode, rawHeaders, socket)
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
onBodySent(chunk) {
|
|
34
|
-
return this.handler.onBodySent(chunk)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
onRequestSent() {
|
|
38
|
-
return this.handler.onRequestSent()
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
onHeaders(statusCode, rawHeaders, resume, statusMessage) {
|
|
42
|
-
return this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage)
|
|
1
|
+
export default (dispatch) => (opts, handler) => {
|
|
2
|
+
if (typeof opts.body !== 'function') {
|
|
3
|
+
return dispatch(opts, handler)
|
|
43
4
|
}
|
|
44
5
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
6
|
+
// TODO (fix): Can we do signal in a better way using
|
|
7
|
+
// a handler?
|
|
48
8
|
|
|
49
|
-
|
|
50
|
-
return this.handler.onComplete(rawTrailers)
|
|
51
|
-
}
|
|
9
|
+
const body = opts.body({ signal: opts.signal })
|
|
52
10
|
|
|
53
|
-
|
|
54
|
-
|
|
11
|
+
if (typeof body.then === 'function') {
|
|
12
|
+
body.then(
|
|
13
|
+
(body) => dispatch({ ...opts, body }, handler),
|
|
14
|
+
(err) => handler.onError(err),
|
|
15
|
+
)
|
|
16
|
+
} else {
|
|
17
|
+
dispatch({ ...opts, body }, handler)
|
|
55
18
|
}
|
|
56
19
|
}
|
|
57
|
-
|
|
58
|
-
export default (dispatch) => (opts, handler) =>
|
|
59
|
-
typeof opts.body === 'function'
|
|
60
|
-
? dispatch(opts, new Handler(opts, { handler, dispatch }))
|
|
61
|
-
: dispatch(opts, handler)
|