@nxtedition/nxt-undici 7.3.15 → 7.3.16

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.
@@ -1,5 +1,8 @@
1
1
  import { DecoratorHandler } from '../utils.js'
2
2
 
3
+ const kGlobalIndex = Symbol('globalIndex')
4
+ const kGlobalArray = Symbol('globalArray')
5
+
3
6
  class Handler extends DecoratorHandler {
4
7
  #opts
5
8
  #logger
@@ -19,9 +22,6 @@ class Handler extends DecoratorHandler {
19
22
  #statusCode
20
23
  #headers
21
24
 
22
- #globalIndex = -1
23
- #globalArray = (globalThis.__undici_requests ??= [])
24
-
25
25
  constructor(logOpts, opts, { handler }) {
26
26
  super(handler)
27
27
 
@@ -35,7 +35,8 @@ class Handler extends DecoratorHandler {
35
35
  this.#logger.debug('upstream request started')
36
36
  this.#timing.created = this.#created + performance.timeOrigin
37
37
 
38
- this.#globalIndex = this.#globalArray.push(this) - 1
38
+ this[kGlobalArray] = globalThis.__undici_requests ??= []
39
+ this[kGlobalIndex] = this[kGlobalArray].push(this) - 1
39
40
  }
40
41
 
41
42
  onConnect(abort) {
@@ -151,13 +152,13 @@ class Handler extends DecoratorHandler {
151
152
  }
152
153
 
153
154
  onDone() {
154
- if (this.#globalIndex !== -1) {
155
- const tmp = this.#globalArray.pop()
155
+ if (this[kGlobalIndex] !== -1) {
156
+ const tmp = this[kGlobalArray].pop()
156
157
  if (tmp !== this) {
157
- this.#globalArray[this.#globalIndex] = tmp
158
- tmp.#globalIndex = this.#globalIndex
158
+ this[kGlobalArray][this[kGlobalIndex]] = tmp
159
+ tmp[kGlobalIndex] = this[kGlobalIndex]
159
160
  }
160
- this.#globalIndex = -1
161
+ this[kGlobalIndex] = -1
161
162
  }
162
163
  }
163
164
  }
@@ -177,6 +177,11 @@ class Handler extends DecoratorHandler {
177
177
  onData(chunk) {
178
178
  if (this.#pos != null) {
179
179
  this.#pos += chunk.byteLength
180
+
181
+ if (this.#end != null && this.#pos > this.#end) {
182
+ this.#maybeError(new Error('Response body exceeded Content-Range'))
183
+ return false
184
+ }
180
185
  }
181
186
 
182
187
  if (this.#statusCode < 400) {
@@ -197,6 +202,10 @@ class Handler extends DecoratorHandler {
197
202
  this.#trailers = trailers
198
203
 
199
204
  if (this.#statusCode < 400) {
205
+ if (this.#end != null && this.#pos !== this.#end) {
206
+ this.#maybeError(new Error('Response body length mismatch with Content-Range'))
207
+ return
208
+ }
200
209
  return super.onComplete(trailers)
201
210
  }
202
211
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "7.3.15",
3
+ "version": "7.3.16",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",