@nxtedition/nxt-undici 2.0.32 → 2.0.33

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.
@@ -20,7 +20,7 @@ function getBody(body, opts) {
20
20
  transform(chunk, encoding, callback) {
21
21
  pos += chunk.length
22
22
  this.push(chunk)
23
- hasher?.update(chunk)
23
+ hasher?.update(chunk, encoding)
24
24
  callback()
25
25
  },
26
26
  flush(callback) {
@@ -1,3 +1,4 @@
1
+ import assert from 'node:assert'
1
2
  import { isDisturbed, retry as retryFn } from '../utils.js'
2
3
 
3
4
  class Handler {
@@ -12,6 +13,12 @@ class Handler {
12
13
  this.reason = null
13
14
  this.aborted = false
14
15
 
16
+ this.statusCode = null
17
+ this.rawHeaders = null
18
+ this.resume = null
19
+ this.statusMessage = null
20
+ this.headers = null
21
+
15
22
  this.handler.onConnect((reason) => {
16
23
  this.aborted = true
17
24
  if (this.abort) {
@@ -35,15 +42,28 @@ class Handler {
35
42
  }
36
43
 
37
44
  onHeaders(statusCode, rawHeaders, resume, statusMessage, headers) {
38
- this.headersSent = true
39
- return this.handler.onHeaders(statusCode, rawHeaders, resume, statusMessage, headers)
45
+ this.statusCode = statusCode
46
+ this.rawHeaders = rawHeaders
47
+ this.resume = resume
48
+ this.statusMessage = statusMessage
49
+ this.headers = headers
50
+
51
+ return true
40
52
  }
41
53
 
42
54
  onData(chunk) {
55
+ if (!this.headersSent) {
56
+ this.sendHeaders()
57
+ }
58
+
43
59
  return this.handler.onData(chunk)
44
60
  }
45
61
 
46
62
  onComplete(rawTrailers) {
63
+ if (!this.headersSent) {
64
+ this.sendHeaders()
65
+ }
66
+
47
67
  return this.handler.onComplete(rawTrailers)
48
68
  }
49
69
 
@@ -71,6 +91,25 @@ class Handler {
71
91
  }
72
92
  })
73
93
  }
94
+
95
+ sendHeaders() {
96
+ assert(!this.headersSent)
97
+
98
+ this.headersSent = true
99
+ this.handler.onHeaders(
100
+ this.statusCode,
101
+ this.rawHeaders,
102
+ this.resume,
103
+ this.statusMessage,
104
+ this.headers,
105
+ )
106
+
107
+ this.statusCode = null
108
+ this.rawHeaders = null
109
+ this.resume = null
110
+ this.statusMessage = null
111
+ this.headers = null
112
+ }
74
113
  }
75
114
 
76
115
  export default (dispatch) => (opts, handler) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nxtedition/nxt-undici",
3
- "version": "2.0.32",
3
+ "version": "2.0.33",
4
4
  "license": "MIT",
5
5
  "author": "Robert Nagy <robert.nagy@boffins.se>",
6
6
  "main": "lib/index.js",