@nxtedition/nxt-undici 1.0.7 → 1.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 CHANGED
@@ -50,6 +50,10 @@ class Readable extends stream.Readable {
50
50
  }
51
51
 
52
52
  async arrayBuffer() {
53
+ return (await this.buffer()).buffer
54
+ }
55
+
56
+ async buffer() {
53
57
  const buffers = []
54
58
  for await (const chunk of this) {
55
59
  buffers.push(chunk)
@@ -57,10 +61,6 @@ class Readable extends stream.Readable {
57
61
  return Buffer.concat(buffers)
58
62
  }
59
63
 
60
- async buffer() {
61
- return Buffer.from(await this.arrayBuffer())
62
- }
63
-
64
64
  async dump() {
65
65
  let n = 0
66
66
  try {
@@ -154,8 +154,8 @@ async function request(url, opts) {
154
154
  dispatch = (opts, handler) => dispatcher.dispatch(opts, handler)
155
155
  dispatch = dispatchers.catch(dispatch)
156
156
  dispatch = dispatchers.abort(dispatch)
157
- dispatch = dispatchers.log(dispatch)
158
157
  dispatch = dispatchers.requestId(dispatch)
158
+ dispatch = dispatchers.log(dispatch)
159
159
  dispatch = dispatchers.responseRetry(dispatch)
160
160
  dispatch = dispatchers.responseStatusRetry(dispatch)
161
161
  dispatch = dispatchers.responseBodyRetry(dispatch)
@@ -210,8 +210,6 @@ async function request(url, opts) {
210
210
  },
211
211
  onBodySent(chunk) {},
212
212
  onHeaders(statusCode, rawHeaders, resume, statusMessage) {
213
- assert(this.abort)
214
-
215
213
  const headers = parseHeaders(rawHeaders)
216
214
 
217
215
  if (statusCode >= 400) {
@@ -236,16 +234,15 @@ async function request(url, opts) {
236
234
 
237
235
  this.resolve(this.body)
238
236
  this.resolve = null
237
+ this.reject = null
239
238
  }
240
239
 
241
240
  return false
242
241
  },
243
242
  onData(chunk) {
244
- assert(this.body)
245
243
  return this.body.push(chunk)
246
244
  },
247
245
  onComplete() {
248
- assert(this.body)
249
246
  this.body.push(null)
250
247
  },
251
248
  onError(err) {
@@ -253,6 +250,7 @@ async function request(url, opts) {
253
250
  this.body.destroy(err)
254
251
  } else {
255
252
  this.reject(err)
253
+ this.resolve = null
256
254
  this.reject = null
257
255
  }
258
256
  },
@@ -116,7 +116,6 @@ class Handler {
116
116
  return this.handler.onError(err)
117
117
  }
118
118
 
119
- // TODO (fix): abort signal?
120
119
  const retryPromise = retryFn(err, this.retryCount++, this.opts)
121
120
  if (retryPromise == null) {
122
121
  return this.handler.onError(err)
@@ -8,6 +8,7 @@ class Handler {
8
8
  this.abort = null
9
9
  this.aborted = false
10
10
  this.reason = null
11
+ this.statusCode = 0
11
12
 
12
13
  this.retryCount = 0
13
14
  this.retryPromise = null
@@ -39,7 +40,7 @@ class Handler {
39
40
  }
40
41
 
41
42
  onHeaders(statusCode, rawHeaders, resume, statusMessage) {
42
- this.aborted = true
43
+ this.statusCode = statusCode
43
44
  return this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage)
44
45
  }
45
46
 
@@ -52,11 +53,10 @@ class Handler {
52
53
  }
53
54
 
54
55
  onError(err) {
55
- if (this.aborted || isDisturbed(this.opts.body)) {
56
+ if (this.aborted || this.statusCode || isDisturbed(this.opts.body)) {
56
57
  return this.handler.onError(err)
57
58
  }
58
59
 
59
- // TODO (fix): abort signal?
60
60
  const retryPromise = retryFn(err, this.retryCount++, this.opts)
61
61
  if (retryPromise == null) {
62
62
  return this.handler.onError(err)
@@ -46,7 +46,6 @@ class Handler {
46
46
 
47
47
  const err = createError(statusCode, { headers: parseHeaders(rawHeaders) })
48
48
 
49
- // TODO (fix): abort signal?
50
49
  const retryPromise = retryFn(err, this.retryCount++, this.opts)
51
50
  if (retryPromise == null) {
52
51
  return this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "1.0.7",
3
+ "version": "1.0.8",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",