@nxtedition/lib 14.1.2 → 14.1.4

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.
Files changed (3) hide show
  1. package/package.json +2 -1
  2. package/stream.js +23 -0
  3. package/undici.js +12 -3
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "14.1.2",
3
+ "version": "14.1.4",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "files": [
@@ -23,6 +23,7 @@
23
23
  "errors.js",
24
24
  "worker.js",
25
25
  "proxy.js",
26
+ "stream.js",
26
27
  "undici.js",
27
28
  "timeline.js",
28
29
  "docker-secrets.js"
package/stream.js ADDED
@@ -0,0 +1,23 @@
1
+ function isReadableNodeStream(obj, strict = false) {
2
+ return !!(
3
+ (
4
+ obj &&
5
+ typeof obj.pipe === 'function' &&
6
+ typeof obj.on === 'function' &&
7
+ (!strict || (typeof obj.pause === 'function' && typeof obj.resume === 'function')) &&
8
+ (!obj._writableState || obj._readableState?.readable !== false) && // Duplex
9
+ (!obj._writableState || obj._readableState)
10
+ ) // Writable has .pipe.
11
+ )
12
+ }
13
+
14
+ function isStream(obj) {
15
+ return (
16
+ obj && typeof obj === 'object' && typeof obj.pipe === 'function' && typeof obj.on === 'function'
17
+ )
18
+ }
19
+
20
+ module.exports = {
21
+ isStream,
22
+ isReadableNodeStream,
23
+ }
package/undici.js CHANGED
@@ -10,7 +10,7 @@ module.exports.request = async function request(
10
10
  {
11
11
  logger,
12
12
  id = xuid(),
13
- retry: { count: maxRetries = 8 } = {},
13
+ retry: { count: maxRetries = 8, status = [] } = {},
14
14
  redirect: { count: maxRedirections = 3 } = {},
15
15
  dispatcher,
16
16
  signal,
@@ -28,7 +28,7 @@ module.exports.request = async function request(
28
28
  method,
29
29
  body,
30
30
  headers: {
31
- 'req-id': id,
31
+ 'request-id': id,
32
32
  'user-agent': userAgent,
33
33
  ...headers,
34
34
  },
@@ -64,6 +64,14 @@ module.exports.request = async function request(
64
64
 
65
65
  assert(ures.statusCode >= 200 && ures.statusCode < 300)
66
66
 
67
+ if (method === 'HEAD' || method === 'DELETE' || method === 'OPTIONS') {
68
+ await ures.body.dump()
69
+ }
70
+
71
+ if (ures.headers['content-length'] === '0') {
72
+ await ures.body.dump()
73
+ }
74
+
67
75
  // TODO (fix): Wrap response to handle error that can continue with range request...
68
76
 
69
77
  return ures
@@ -96,7 +104,8 @@ module.exports.request = async function request(
96
104
  err.statusCode !== 429 &&
97
105
  err.statusCode !== 502 &&
98
106
  err.statusCode !== 503 &&
99
- err.statusCode !== 504
107
+ err.statusCode !== 504 &&
108
+ !status.includes(err.statusCode)
100
109
  ) {
101
110
  throw err
102
111
  }