@nxtedition/lib 15.0.29 → 15.0.30

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.
@@ -121,6 +121,18 @@ async function request(urlOrOpts, opts = {}) {
121
121
  logger: opts.logger,
122
122
  }
123
123
 
124
+ const expectsPayload = opts.method === 'PUT' || opts.method === 'POST' || opts.method === 'PATCH'
125
+
126
+ if (opts.headers['content-length'] === '0' && !expectsPayload) {
127
+ // https://tools.ietf.org/html/rfc7230#section-3.3.2
128
+ // A user agent SHOULD NOT send a Content-Length header field when
129
+ // the request message does not contain a payload body and the method
130
+ // semantics do not anticipate such a body.
131
+
132
+ // undici will error if provided an unexpected content-length: 0 header.
133
+ delete opts.headers['content-length']
134
+ }
135
+
124
136
  const dispatcher = opts.dispatcher ?? undici.getGlobalDispatcher()
125
137
 
126
138
  return new Promise((resolve) => {
@@ -1,5 +1,6 @@
1
1
  const { parseHeaders } = require('../../../http.js')
2
2
  const xuid = require('xuid')
3
+ const { performance } = require('perf_hooks')
3
4
 
4
5
  class Handler {
5
6
  constructor(opts, { handler }) {
@@ -9,10 +10,12 @@ class Handler {
9
10
  this.aborted = false
10
11
  this.logger = opts.logger.child({ ureq: { id: opts.id } })
11
12
  this.pos = 0
13
+ this.startTime = 0
12
14
  }
13
15
 
14
16
  onConnect(abort) {
15
17
  this.abort = abort
18
+ this.startTime = performance.now()
16
19
  this.logger.debug({ ureq: this.opts }, 'upstream request started')
17
20
  this.handler.onConnect?.((reason) => {
18
21
  this.aborted = true
@@ -26,7 +29,10 @@ class Handler {
26
29
 
27
30
  onHeaders(statusCode, rawHeaders, resume, statusMessage) {
28
31
  this.logger.debug(
29
- { ures: { statusCode, headers: parseHeaders(rawHeaders) } },
32
+ {
33
+ ures: { statusCode, headers: parseHeaders(rawHeaders) },
34
+ elapsedTime: this.startTime - performance.now(),
35
+ },
30
36
  'upstream request response',
31
37
  )
32
38
  return this.handler.onHeaders?.(statusCode, rawHeaders, resume, statusMessage)
@@ -38,15 +44,24 @@ class Handler {
38
44
  }
39
45
 
40
46
  onComplete(rawTrailers) {
41
- this.logger.debug({ bytesRead: this.pos }, 'upstream request completed')
47
+ this.logger.debug(
48
+ { bytesRead: this.pos, elapsedTime: this.startTime - performance.now() },
49
+ 'upstream request completed',
50
+ )
42
51
  return this.handler.onComplete?.(rawTrailers)
43
52
  }
44
53
 
45
54
  onError(err) {
46
55
  if (this.aborted) {
47
- this.logger.debug({ bytesRead: this.pos, err }, 'upstream request aborted')
56
+ this.logger.debug(
57
+ { bytesRead: this.pos, elapsedTime: this.startTime - performance.now(), err },
58
+ 'upstream request aborted',
59
+ )
48
60
  } else {
49
- this.logger.error({ bytesRead: this.pos, err }, 'upstream request failed')
61
+ this.logger.error(
62
+ { bytesRead: this.pos, elapsedTime: this.startTime - performance.now(), err },
63
+ 'upstream request failed',
64
+ )
50
65
  }
51
66
  return this.handler.onError?.(err)
52
67
  }
@@ -136,6 +136,7 @@ class Handler {
136
136
  ...this.opts,
137
137
  headers: {
138
138
  ...this.opts.headers,
139
+ 'if-match': this.etag,
139
140
  range: `bytes=${this.pos}-${this.end ?? ''}`,
140
141
  },
141
142
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/lib",
3
- "version": "15.0.29",
3
+ "version": "15.0.30",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "files": [
@@ -9,7 +9,7 @@
9
9
  "rxjs/*",
10
10
  "util/*",
11
11
  "lib/*",
12
- "undici/*",
12
+ "undici.js",
13
13
  "http-client.js",
14
14
  "subtract-ranges.js",
15
15
  "serializers.js",
package/undici.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require('./lib/undici/index.js')