@nxtedition/nxt-undici 5.0.0 → 5.0.1

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.
@@ -31,7 +31,7 @@ class CacheHandler {
31
31
  const maxEntrySize = this.#store.maxEntrySize ?? Infinity
32
32
 
33
33
  if (
34
- contentLength < maxEntrySize &&
34
+ (!contentLength || contentLength < maxEntrySize) &&
35
35
  cacheControl &&
36
36
  cacheControl.public &&
37
37
  !cacheControl.private &&
@@ -59,7 +59,7 @@ class Handler extends DecoratorHandler {
59
59
 
60
60
  this.#logger.debug(
61
61
  {
62
- ureq: { id: this.#opts.id, url: this.#opts.url },
62
+ ureq: { id: this.#opts.id, url: String(this.#opts.url) },
63
63
  ures: { statusCode, headers },
64
64
  elapsedTime: this.#timing.headers,
65
65
  },
package/lib/request.js CHANGED
@@ -6,7 +6,7 @@ import { BodyReadable as Readable } from './readable.js'
6
6
  function noop() {}
7
7
 
8
8
  export class RequestHandler {
9
- constructor(opts, callback) {
9
+ constructor(opts, resolve) {
10
10
  if (!opts || typeof opts !== 'object') {
11
11
  throw new InvalidArgumentError('invalid opts')
12
12
  }
@@ -14,8 +14,8 @@ export class RequestHandler {
14
14
  const { signal, method, body, highWaterMark } = opts
15
15
 
16
16
  try {
17
- if (typeof callback !== 'function') {
18
- throw new InvalidArgumentError('invalid callback')
17
+ if (typeof resolve !== 'function') {
18
+ throw new InvalidArgumentError('invalid resolve')
19
19
  }
20
20
 
21
21
  if (highWaterMark && (typeof highWaterMark !== 'number' || highWaterMark < 0)) {
@@ -41,7 +41,7 @@ export class RequestHandler {
41
41
  }
42
42
 
43
43
  this.method = method
44
- this.callback = callback
44
+ this.resolve = resolve
45
45
  this.res = null
46
46
  this.abort = null
47
47
  this.body = body
@@ -71,13 +71,13 @@ export class RequestHandler {
71
71
  return
72
72
  }
73
73
 
74
- assert(this.callback)
74
+ assert(this.resolve)
75
75
 
76
76
  this.abort = abort
77
77
  }
78
78
 
79
79
  onHeaders(statusCode, rawHeaders, resume, headers = parseHeaders(rawHeaders)) {
80
- const { callback, abort, highWaterMark } = this
80
+ const { resolve, abort, highWaterMark } = this
81
81
 
82
82
  if (statusCode < 200) {
83
83
  return true
@@ -98,11 +98,11 @@ export class RequestHandler {
98
98
  this.removeAbortListener = undefined
99
99
  }
100
100
 
101
- this.callback = null
101
+ this.resolve = null
102
102
  this.res = res
103
103
 
104
- if (callback !== null) {
105
- callback(null, { statusCode, headers, body: res })
104
+ if (resolve !== null) {
105
+ resolve({ statusCode, headers, body: res })
106
106
  }
107
107
  }
108
108
 
@@ -115,13 +115,13 @@ export class RequestHandler {
115
115
  }
116
116
 
117
117
  onError(err) {
118
- const { res, callback, body } = this
118
+ const { res, resolve, body } = this
119
119
 
120
- if (callback) {
120
+ if (resolve) {
121
121
  // TODO: Does this need queueMicrotask?
122
- this.callback = null
122
+ this.resolve = null
123
123
  queueMicrotask(() => {
124
- callback(err)
124
+ resolve(Promise.reject(err))
125
125
  })
126
126
  }
127
127
 
@@ -149,7 +149,7 @@ export class RequestHandler {
149
149
  }
150
150
 
151
151
  export function request(dispatch, url, opts) {
152
- return new Promise((resolve, reject) => {
152
+ return new Promise((resolve) => {
153
153
  if (typeof url === 'string') {
154
154
  opts = { url: new URL(url), ...opts }
155
155
  } else if (url instanceof URL) {
@@ -162,15 +162,6 @@ export function request(dispatch, url, opts) {
162
162
  opts = url
163
163
  }
164
164
 
165
- dispatch(
166
- opts,
167
- new RequestHandler(opts, (err, res) => {
168
- if (err) {
169
- reject(err)
170
- } else {
171
- resolve(res)
172
- }
173
- }),
174
- )
165
+ dispatch(opts, new RequestHandler(opts, resolve))
175
166
  })
176
167
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "5.0.0",
3
+ "version": "5.0.1",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",