deepv-code 1.0.182 → 1.0.185
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.
- package/bundle/dvcode.js +757 -753
- package/package.json +1 -1
- package/bundle/assets/help/README.md +0 -113
- package/bundle/assets/sounds/README.md +0 -74
- package/bundle/node_modules/undici/LICENSE +0 -21
- package/bundle/node_modules/undici/README.md +0 -472
- package/bundle/node_modules/undici/docs/docs/api/Agent.md +0 -83
- package/bundle/node_modules/undici/docs/docs/api/BalancedPool.md +0 -99
- package/bundle/node_modules/undici/docs/docs/api/CacheStorage.md +0 -30
- package/bundle/node_modules/undici/docs/docs/api/CacheStore.md +0 -151
- package/bundle/node_modules/undici/docs/docs/api/Client.md +0 -281
- package/bundle/node_modules/undici/docs/docs/api/ClientStats.md +0 -27
- package/bundle/node_modules/undici/docs/docs/api/Connector.md +0 -115
- package/bundle/node_modules/undici/docs/docs/api/ContentType.md +0 -57
- package/bundle/node_modules/undici/docs/docs/api/Cookies.md +0 -101
- package/bundle/node_modules/undici/docs/docs/api/Debug.md +0 -62
- package/bundle/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +0 -204
- package/bundle/node_modules/undici/docs/docs/api/Dispatcher.md +0 -1200
- package/bundle/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +0 -159
- package/bundle/node_modules/undici/docs/docs/api/Errors.md +0 -49
- package/bundle/node_modules/undici/docs/docs/api/EventSource.md +0 -45
- package/bundle/node_modules/undici/docs/docs/api/Fetch.md +0 -52
- package/bundle/node_modules/undici/docs/docs/api/H2CClient.md +0 -262
- package/bundle/node_modules/undici/docs/docs/api/MockAgent.md +0 -603
- package/bundle/node_modules/undici/docs/docs/api/MockCallHistory.md +0 -197
- package/bundle/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +0 -43
- package/bundle/node_modules/undici/docs/docs/api/MockClient.md +0 -77
- package/bundle/node_modules/undici/docs/docs/api/MockErrors.md +0 -12
- package/bundle/node_modules/undici/docs/docs/api/MockPool.md +0 -548
- package/bundle/node_modules/undici/docs/docs/api/Pool.md +0 -84
- package/bundle/node_modules/undici/docs/docs/api/PoolStats.md +0 -35
- package/bundle/node_modules/undici/docs/docs/api/ProxyAgent.md +0 -227
- package/bundle/node_modules/undici/docs/docs/api/RedirectHandler.md +0 -96
- package/bundle/node_modules/undici/docs/docs/api/RetryAgent.md +0 -45
- package/bundle/node_modules/undici/docs/docs/api/RetryHandler.md +0 -117
- package/bundle/node_modules/undici/docs/docs/api/Util.md +0 -25
- package/bundle/node_modules/undici/docs/docs/api/WebSocket.md +0 -85
- package/bundle/node_modules/undici/docs/docs/api/api-lifecycle.md +0 -91
- package/bundle/node_modules/undici/docs/docs/best-practices/client-certificate.md +0 -64
- package/bundle/node_modules/undici/docs/docs/best-practices/mocking-request.md +0 -190
- package/bundle/node_modules/undici/docs/docs/best-practices/proxy.md +0 -127
- package/bundle/node_modules/undici/docs/docs/best-practices/writing-tests.md +0 -20
- package/bundle/node_modules/undici/index-fetch.js +0 -35
- package/bundle/node_modules/undici/index.d.ts +0 -3
- package/bundle/node_modules/undici/index.js +0 -183
- package/bundle/node_modules/undici/lib/api/abort-signal.js +0 -59
- package/bundle/node_modules/undici/lib/api/api-connect.js +0 -110
- package/bundle/node_modules/undici/lib/api/api-pipeline.js +0 -252
- package/bundle/node_modules/undici/lib/api/api-request.js +0 -199
- package/bundle/node_modules/undici/lib/api/api-stream.js +0 -209
- package/bundle/node_modules/undici/lib/api/api-upgrade.js +0 -110
- package/bundle/node_modules/undici/lib/api/index.js +0 -7
- package/bundle/node_modules/undici/lib/api/readable.js +0 -558
- package/bundle/node_modules/undici/lib/api/util.js +0 -95
- package/bundle/node_modules/undici/lib/cache/memory-cache-store.js +0 -234
- package/bundle/node_modules/undici/lib/cache/sqlite-cache-store.js +0 -461
- package/bundle/node_modules/undici/lib/core/connect.js +0 -164
- package/bundle/node_modules/undici/lib/core/constants.js +0 -143
- package/bundle/node_modules/undici/lib/core/diagnostics.js +0 -196
- package/bundle/node_modules/undici/lib/core/errors.js +0 -244
- package/bundle/node_modules/undici/lib/core/request.js +0 -397
- package/bundle/node_modules/undici/lib/core/symbols.js +0 -68
- package/bundle/node_modules/undici/lib/core/tree.js +0 -160
- package/bundle/node_modules/undici/lib/core/util.js +0 -988
- package/bundle/node_modules/undici/lib/dispatcher/agent.js +0 -135
- package/bundle/node_modules/undici/lib/dispatcher/balanced-pool.js +0 -206
- package/bundle/node_modules/undici/lib/dispatcher/client-h1.js +0 -1615
- package/bundle/node_modules/undici/lib/dispatcher/client-h2.js +0 -798
- package/bundle/node_modules/undici/lib/dispatcher/client.js +0 -614
- package/bundle/node_modules/undici/lib/dispatcher/dispatcher-base.js +0 -161
- package/bundle/node_modules/undici/lib/dispatcher/dispatcher.js +0 -48
- package/bundle/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +0 -151
- package/bundle/node_modules/undici/lib/dispatcher/fixed-queue.js +0 -159
- package/bundle/node_modules/undici/lib/dispatcher/h2c-client.js +0 -122
- package/bundle/node_modules/undici/lib/dispatcher/pool-base.js +0 -191
- package/bundle/node_modules/undici/lib/dispatcher/pool.js +0 -118
- package/bundle/node_modules/undici/lib/dispatcher/proxy-agent.js +0 -275
- package/bundle/node_modules/undici/lib/dispatcher/retry-agent.js +0 -35
- package/bundle/node_modules/undici/lib/global.js +0 -32
- package/bundle/node_modules/undici/lib/handler/cache-handler.js +0 -448
- package/bundle/node_modules/undici/lib/handler/cache-revalidation-handler.js +0 -124
- package/bundle/node_modules/undici/lib/handler/decorator-handler.js +0 -67
- package/bundle/node_modules/undici/lib/handler/redirect-handler.js +0 -227
- package/bundle/node_modules/undici/lib/handler/retry-handler.js +0 -342
- package/bundle/node_modules/undici/lib/handler/unwrap-handler.js +0 -96
- package/bundle/node_modules/undici/lib/handler/wrap-handler.js +0 -95
- package/bundle/node_modules/undici/lib/interceptor/cache.js +0 -372
- package/bundle/node_modules/undici/lib/interceptor/dns.js +0 -432
- package/bundle/node_modules/undici/lib/interceptor/dump.js +0 -111
- package/bundle/node_modules/undici/lib/interceptor/redirect.js +0 -21
- package/bundle/node_modules/undici/lib/interceptor/response-error.js +0 -95
- package/bundle/node_modules/undici/lib/interceptor/retry.js +0 -19
- package/bundle/node_modules/undici/lib/llhttp/.gitkeep +0 -0
- package/bundle/node_modules/undici/lib/llhttp/constants.d.ts +0 -97
- package/bundle/node_modules/undici/lib/llhttp/constants.js +0 -498
- package/bundle/node_modules/undici/lib/llhttp/constants.js.map +0 -1
- package/bundle/node_modules/undici/lib/llhttp/llhttp-wasm.js +0 -15
- package/bundle/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +0 -15
- package/bundle/node_modules/undici/lib/llhttp/utils.d.ts +0 -2
- package/bundle/node_modules/undici/lib/llhttp/utils.js +0 -15
- package/bundle/node_modules/undici/lib/llhttp/utils.js.map +0 -1
- package/bundle/node_modules/undici/lib/mock/mock-agent.js +0 -224
- package/bundle/node_modules/undici/lib/mock/mock-call-history.js +0 -248
- package/bundle/node_modules/undici/lib/mock/mock-client.js +0 -64
- package/bundle/node_modules/undici/lib/mock/mock-errors.js +0 -19
- package/bundle/node_modules/undici/lib/mock/mock-interceptor.js +0 -209
- package/bundle/node_modules/undici/lib/mock/mock-pool.js +0 -64
- package/bundle/node_modules/undici/lib/mock/mock-symbols.js +0 -31
- package/bundle/node_modules/undici/lib/mock/mock-utils.js +0 -433
- package/bundle/node_modules/undici/lib/mock/pending-interceptors-formatter.js +0 -43
- package/bundle/node_modules/undici/lib/util/cache.js +0 -368
- package/bundle/node_modules/undici/lib/util/date.js +0 -259
- package/bundle/node_modules/undici/lib/util/stats.js +0 -32
- package/bundle/node_modules/undici/lib/util/timers.js +0 -423
- package/bundle/node_modules/undici/lib/web/cache/cache.js +0 -862
- package/bundle/node_modules/undici/lib/web/cache/cachestorage.js +0 -152
- package/bundle/node_modules/undici/lib/web/cache/util.js +0 -45
- package/bundle/node_modules/undici/lib/web/cookies/constants.js +0 -12
- package/bundle/node_modules/undici/lib/web/cookies/index.js +0 -199
- package/bundle/node_modules/undici/lib/web/cookies/parse.js +0 -322
- package/bundle/node_modules/undici/lib/web/cookies/util.js +0 -282
- package/bundle/node_modules/undici/lib/web/eventsource/eventsource-stream.js +0 -399
- package/bundle/node_modules/undici/lib/web/eventsource/eventsource.js +0 -484
- package/bundle/node_modules/undici/lib/web/eventsource/util.js +0 -37
- package/bundle/node_modules/undici/lib/web/fetch/LICENSE +0 -21
- package/bundle/node_modules/undici/lib/web/fetch/body.js +0 -532
- package/bundle/node_modules/undici/lib/web/fetch/constants.js +0 -131
- package/bundle/node_modules/undici/lib/web/fetch/data-url.js +0 -744
- package/bundle/node_modules/undici/lib/web/fetch/dispatcher-weakref.js +0 -46
- package/bundle/node_modules/undici/lib/web/fetch/formdata-parser.js +0 -501
- package/bundle/node_modules/undici/lib/web/fetch/formdata.js +0 -263
- package/bundle/node_modules/undici/lib/web/fetch/global.js +0 -40
- package/bundle/node_modules/undici/lib/web/fetch/headers.js +0 -719
- package/bundle/node_modules/undici/lib/web/fetch/index.js +0 -2258
- package/bundle/node_modules/undici/lib/web/fetch/request.js +0 -1099
- package/bundle/node_modules/undici/lib/web/fetch/response.js +0 -636
- package/bundle/node_modules/undici/lib/web/fetch/util.js +0 -1782
- package/bundle/node_modules/undici/lib/web/fetch/webidl.js +0 -740
- package/bundle/node_modules/undici/lib/web/websocket/connection.js +0 -325
- package/bundle/node_modules/undici/lib/web/websocket/constants.js +0 -126
- package/bundle/node_modules/undici/lib/web/websocket/events.js +0 -331
- package/bundle/node_modules/undici/lib/web/websocket/frame.js +0 -138
- package/bundle/node_modules/undici/lib/web/websocket/permessage-deflate.js +0 -70
- package/bundle/node_modules/undici/lib/web/websocket/receiver.js +0 -454
- package/bundle/node_modules/undici/lib/web/websocket/sender.js +0 -109
- package/bundle/node_modules/undici/lib/web/websocket/stream/websocketerror.js +0 -83
- package/bundle/node_modules/undici/lib/web/websocket/stream/websocketstream.js +0 -485
- package/bundle/node_modules/undici/lib/web/websocket/util.js +0 -338
- package/bundle/node_modules/undici/lib/web/websocket/websocket.js +0 -686
- package/bundle/node_modules/undici/package.json +0 -149
- package/bundle/node_modules/undici/scripts/strip-comments.js +0 -10
- package/bundle/node_modules/undici/types/README.md +0 -6
- package/bundle/node_modules/undici/types/agent.d.ts +0 -35
- package/bundle/node_modules/undici/types/api.d.ts +0 -43
- package/bundle/node_modules/undici/types/balanced-pool.d.ts +0 -29
- package/bundle/node_modules/undici/types/cache-interceptor.d.ts +0 -172
- package/bundle/node_modules/undici/types/cache.d.ts +0 -36
- package/bundle/node_modules/undici/types/client-stats.d.ts +0 -15
- package/bundle/node_modules/undici/types/client.d.ts +0 -110
- package/bundle/node_modules/undici/types/connector.d.ts +0 -34
- package/bundle/node_modules/undici/types/content-type.d.ts +0 -21
- package/bundle/node_modules/undici/types/cookies.d.ts +0 -30
- package/bundle/node_modules/undici/types/diagnostics-channel.d.ts +0 -66
- package/bundle/node_modules/undici/types/dispatcher.d.ts +0 -281
- package/bundle/node_modules/undici/types/env-http-proxy-agent.d.ts +0 -21
- package/bundle/node_modules/undici/types/errors.d.ts +0 -171
- package/bundle/node_modules/undici/types/eventsource.d.ts +0 -61
- package/bundle/node_modules/undici/types/fetch.d.ts +0 -210
- package/bundle/node_modules/undici/types/formdata.d.ts +0 -108
- package/bundle/node_modules/undici/types/global-dispatcher.d.ts +0 -9
- package/bundle/node_modules/undici/types/global-origin.d.ts +0 -7
- package/bundle/node_modules/undici/types/h2c-client.d.ts +0 -75
- package/bundle/node_modules/undici/types/handlers.d.ts +0 -15
- package/bundle/node_modules/undici/types/header.d.ts +0 -160
- package/bundle/node_modules/undici/types/index.d.ts +0 -75
- package/bundle/node_modules/undici/types/interceptors.d.ts +0 -34
- package/bundle/node_modules/undici/types/mock-agent.d.ts +0 -68
- package/bundle/node_modules/undici/types/mock-call-history.d.ts +0 -111
- package/bundle/node_modules/undici/types/mock-client.d.ts +0 -25
- package/bundle/node_modules/undici/types/mock-errors.d.ts +0 -12
- package/bundle/node_modules/undici/types/mock-interceptor.d.ts +0 -93
- package/bundle/node_modules/undici/types/mock-pool.d.ts +0 -25
- package/bundle/node_modules/undici/types/patch.d.ts +0 -29
- package/bundle/node_modules/undici/types/pool-stats.d.ts +0 -19
- package/bundle/node_modules/undici/types/pool.d.ts +0 -41
- package/bundle/node_modules/undici/types/proxy-agent.d.ts +0 -29
- package/bundle/node_modules/undici/types/readable.d.ts +0 -68
- package/bundle/node_modules/undici/types/retry-agent.d.ts +0 -8
- package/bundle/node_modules/undici/types/retry-handler.d.ts +0 -116
- package/bundle/node_modules/undici/types/util.d.ts +0 -18
- package/bundle/node_modules/undici/types/utility.d.ts +0 -7
- package/bundle/node_modules/undici/types/webidl.d.ts +0 -266
- package/bundle/node_modules/undici/types/websocket.d.ts +0 -184
|
@@ -1,558 +0,0 @@
|
|
|
1
|
-
// Ported from https://github.com/nodejs/undici/pull/907
|
|
2
|
-
|
|
3
|
-
'use strict'
|
|
4
|
-
|
|
5
|
-
const assert = require('node:assert')
|
|
6
|
-
const { Readable } = require('node:stream')
|
|
7
|
-
const { RequestAbortedError, NotSupportedError, InvalidArgumentError, AbortError } = require('../core/errors')
|
|
8
|
-
const util = require('../core/util')
|
|
9
|
-
const { ReadableStreamFrom } = require('../core/util')
|
|
10
|
-
|
|
11
|
-
const kConsume = Symbol('kConsume')
|
|
12
|
-
const kReading = Symbol('kReading')
|
|
13
|
-
const kBody = Symbol('kBody')
|
|
14
|
-
const kAbort = Symbol('kAbort')
|
|
15
|
-
const kContentType = Symbol('kContentType')
|
|
16
|
-
const kContentLength = Symbol('kContentLength')
|
|
17
|
-
const kUsed = Symbol('kUsed')
|
|
18
|
-
const kBytesRead = Symbol('kBytesRead')
|
|
19
|
-
|
|
20
|
-
const noop = () => {}
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @class
|
|
24
|
-
* @extends {Readable}
|
|
25
|
-
* @see https://fetch.spec.whatwg.org/#body
|
|
26
|
-
*/
|
|
27
|
-
class BodyReadable extends Readable {
|
|
28
|
-
/**
|
|
29
|
-
* @param {object} opts
|
|
30
|
-
* @param {(this: Readable, size: number) => void} opts.resume
|
|
31
|
-
* @param {() => (void | null)} opts.abort
|
|
32
|
-
* @param {string} [opts.contentType = '']
|
|
33
|
-
* @param {number} [opts.contentLength]
|
|
34
|
-
* @param {number} [opts.highWaterMark = 64 * 1024]
|
|
35
|
-
*/
|
|
36
|
-
constructor ({
|
|
37
|
-
resume,
|
|
38
|
-
abort,
|
|
39
|
-
contentType = '',
|
|
40
|
-
contentLength,
|
|
41
|
-
highWaterMark = 64 * 1024 // Same as nodejs fs streams.
|
|
42
|
-
}) {
|
|
43
|
-
super({
|
|
44
|
-
autoDestroy: true,
|
|
45
|
-
read: resume,
|
|
46
|
-
highWaterMark
|
|
47
|
-
})
|
|
48
|
-
|
|
49
|
-
this._readableState.dataEmitted = false
|
|
50
|
-
|
|
51
|
-
this[kAbort] = abort
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* @type {Consume | null}
|
|
55
|
-
*/
|
|
56
|
-
this[kConsume] = null
|
|
57
|
-
this[kBytesRead] = 0
|
|
58
|
-
/**
|
|
59
|
-
* @type {ReadableStream|null}
|
|
60
|
-
*/
|
|
61
|
-
this[kBody] = null
|
|
62
|
-
this[kUsed] = false
|
|
63
|
-
this[kContentType] = contentType
|
|
64
|
-
this[kContentLength] = Number.isFinite(contentLength) ? contentLength : null
|
|
65
|
-
|
|
66
|
-
// Is stream being consumed through Readable API?
|
|
67
|
-
// This is an optimization so that we avoid checking
|
|
68
|
-
// for 'data' and 'readable' listeners in the hot path
|
|
69
|
-
// inside push().
|
|
70
|
-
this[kReading] = false
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
/**
|
|
74
|
-
* @param {Error|null} err
|
|
75
|
-
* @param {(error:(Error|null)) => void} callback
|
|
76
|
-
* @returns {void}
|
|
77
|
-
*/
|
|
78
|
-
_destroy (err, callback) {
|
|
79
|
-
if (!err && !this._readableState.endEmitted) {
|
|
80
|
-
err = new RequestAbortedError()
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (err) {
|
|
84
|
-
this[kAbort]()
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
// Workaround for Node "bug". If the stream is destroyed in same
|
|
88
|
-
// tick as it is created, then a user who is waiting for a
|
|
89
|
-
// promise (i.e micro tick) for installing an 'error' listener will
|
|
90
|
-
// never get a chance and will always encounter an unhandled exception.
|
|
91
|
-
if (!this[kUsed]) {
|
|
92
|
-
setImmediate(() => {
|
|
93
|
-
callback(err)
|
|
94
|
-
})
|
|
95
|
-
} else {
|
|
96
|
-
callback(err)
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
/**
|
|
101
|
-
* @param {string} event
|
|
102
|
-
* @param {(...args: any[]) => void} listener
|
|
103
|
-
* @returns {this}
|
|
104
|
-
*/
|
|
105
|
-
on (event, listener) {
|
|
106
|
-
if (event === 'data' || event === 'readable') {
|
|
107
|
-
this[kReading] = true
|
|
108
|
-
this[kUsed] = true
|
|
109
|
-
}
|
|
110
|
-
return super.on(event, listener)
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* @param {string} event
|
|
115
|
-
* @param {(...args: any[]) => void} listener
|
|
116
|
-
* @returns {this}
|
|
117
|
-
*/
|
|
118
|
-
addListener (event, listener) {
|
|
119
|
-
return this.on(event, listener)
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
/**
|
|
123
|
-
* @param {string|symbol} event
|
|
124
|
-
* @param {(...args: any[]) => void} listener
|
|
125
|
-
* @returns {this}
|
|
126
|
-
*/
|
|
127
|
-
off (event, listener) {
|
|
128
|
-
const ret = super.off(event, listener)
|
|
129
|
-
if (event === 'data' || event === 'readable') {
|
|
130
|
-
this[kReading] = (
|
|
131
|
-
this.listenerCount('data') > 0 ||
|
|
132
|
-
this.listenerCount('readable') > 0
|
|
133
|
-
)
|
|
134
|
-
}
|
|
135
|
-
return ret
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* @param {string|symbol} event
|
|
140
|
-
* @param {(...args: any[]) => void} listener
|
|
141
|
-
* @returns {this}
|
|
142
|
-
*/
|
|
143
|
-
removeListener (event, listener) {
|
|
144
|
-
return this.off(event, listener)
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* @param {Buffer|null} chunk
|
|
149
|
-
* @returns {boolean}
|
|
150
|
-
*/
|
|
151
|
-
push (chunk) {
|
|
152
|
-
this[kBytesRead] += chunk ? chunk.length : 0
|
|
153
|
-
|
|
154
|
-
if (this[kConsume] && chunk !== null) {
|
|
155
|
-
consumePush(this[kConsume], chunk)
|
|
156
|
-
return this[kReading] ? super.push(chunk) : true
|
|
157
|
-
}
|
|
158
|
-
return super.push(chunk)
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* Consumes and returns the body as a string.
|
|
163
|
-
*
|
|
164
|
-
* @see https://fetch.spec.whatwg.org/#dom-body-text
|
|
165
|
-
* @returns {Promise<string>}
|
|
166
|
-
*/
|
|
167
|
-
text () {
|
|
168
|
-
return consume(this, 'text')
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* Consumes and returns the body as a JavaScript Object.
|
|
173
|
-
*
|
|
174
|
-
* @see https://fetch.spec.whatwg.org/#dom-body-json
|
|
175
|
-
* @returns {Promise<unknown>}
|
|
176
|
-
*/
|
|
177
|
-
json () {
|
|
178
|
-
return consume(this, 'json')
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
/**
|
|
182
|
-
* Consumes and returns the body as a Blob
|
|
183
|
-
*
|
|
184
|
-
* @see https://fetch.spec.whatwg.org/#dom-body-blob
|
|
185
|
-
* @returns {Promise<Blob>}
|
|
186
|
-
*/
|
|
187
|
-
blob () {
|
|
188
|
-
return consume(this, 'blob')
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Consumes and returns the body as an Uint8Array.
|
|
193
|
-
*
|
|
194
|
-
* @see https://fetch.spec.whatwg.org/#dom-body-bytes
|
|
195
|
-
* @returns {Promise<Uint8Array>}
|
|
196
|
-
*/
|
|
197
|
-
bytes () {
|
|
198
|
-
return consume(this, 'bytes')
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
/**
|
|
202
|
-
* Consumes and returns the body as an ArrayBuffer.
|
|
203
|
-
*
|
|
204
|
-
* @see https://fetch.spec.whatwg.org/#dom-body-arraybuffer
|
|
205
|
-
* @returns {Promise<ArrayBuffer>}
|
|
206
|
-
*/
|
|
207
|
-
arrayBuffer () {
|
|
208
|
-
return consume(this, 'arrayBuffer')
|
|
209
|
-
}
|
|
210
|
-
|
|
211
|
-
/**
|
|
212
|
-
* Not implemented
|
|
213
|
-
*
|
|
214
|
-
* @see https://fetch.spec.whatwg.org/#dom-body-formdata
|
|
215
|
-
* @throws {NotSupportedError}
|
|
216
|
-
*/
|
|
217
|
-
async formData () {
|
|
218
|
-
// TODO: Implement.
|
|
219
|
-
throw new NotSupportedError()
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
/**
|
|
223
|
-
* Returns true if the body is not null and the body has been consumed.
|
|
224
|
-
* Otherwise, returns false.
|
|
225
|
-
*
|
|
226
|
-
* @see https://fetch.spec.whatwg.org/#dom-body-bodyused
|
|
227
|
-
* @readonly
|
|
228
|
-
* @returns {boolean}
|
|
229
|
-
*/
|
|
230
|
-
get bodyUsed () {
|
|
231
|
-
return util.isDisturbed(this)
|
|
232
|
-
}
|
|
233
|
-
|
|
234
|
-
/**
|
|
235
|
-
* @see https://fetch.spec.whatwg.org/#dom-body-body
|
|
236
|
-
* @readonly
|
|
237
|
-
* @returns {ReadableStream}
|
|
238
|
-
*/
|
|
239
|
-
get body () {
|
|
240
|
-
if (!this[kBody]) {
|
|
241
|
-
this[kBody] = ReadableStreamFrom(this)
|
|
242
|
-
if (this[kConsume]) {
|
|
243
|
-
// TODO: Is this the best way to force a lock?
|
|
244
|
-
this[kBody].getReader() // Ensure stream is locked.
|
|
245
|
-
assert(this[kBody].locked)
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
return this[kBody]
|
|
249
|
-
}
|
|
250
|
-
|
|
251
|
-
/**
|
|
252
|
-
* Dumps the response body by reading `limit` number of bytes.
|
|
253
|
-
* @param {object} opts
|
|
254
|
-
* @param {number} [opts.limit = 131072] Number of bytes to read.
|
|
255
|
-
* @param {AbortSignal} [opts.signal] An AbortSignal to cancel the dump.
|
|
256
|
-
* @returns {Promise<null>}
|
|
257
|
-
*/
|
|
258
|
-
async dump (opts) {
|
|
259
|
-
const signal = opts?.signal
|
|
260
|
-
|
|
261
|
-
if (signal != null && (typeof signal !== 'object' || !('aborted' in signal))) {
|
|
262
|
-
throw new InvalidArgumentError('signal must be an AbortSignal')
|
|
263
|
-
}
|
|
264
|
-
|
|
265
|
-
const limit = opts?.limit && Number.isFinite(opts.limit)
|
|
266
|
-
? opts.limit
|
|
267
|
-
: 128 * 1024
|
|
268
|
-
|
|
269
|
-
signal?.throwIfAborted()
|
|
270
|
-
|
|
271
|
-
if (this._readableState.closeEmitted) {
|
|
272
|
-
return null
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
return await new Promise((resolve, reject) => {
|
|
276
|
-
if (
|
|
277
|
-
(this[kContentLength] && (this[kContentLength] > limit)) ||
|
|
278
|
-
this[kBytesRead] > limit
|
|
279
|
-
) {
|
|
280
|
-
this.destroy(new AbortError())
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
if (signal) {
|
|
284
|
-
const onAbort = () => {
|
|
285
|
-
this.destroy(signal.reason ?? new AbortError())
|
|
286
|
-
}
|
|
287
|
-
signal.addEventListener('abort', onAbort)
|
|
288
|
-
this
|
|
289
|
-
.on('close', function () {
|
|
290
|
-
signal.removeEventListener('abort', onAbort)
|
|
291
|
-
if (signal.aborted) {
|
|
292
|
-
reject(signal.reason ?? new AbortError())
|
|
293
|
-
} else {
|
|
294
|
-
resolve(null)
|
|
295
|
-
}
|
|
296
|
-
})
|
|
297
|
-
} else {
|
|
298
|
-
this.on('close', resolve)
|
|
299
|
-
}
|
|
300
|
-
|
|
301
|
-
this
|
|
302
|
-
.on('error', noop)
|
|
303
|
-
.on('data', () => {
|
|
304
|
-
if (this[kBytesRead] > limit) {
|
|
305
|
-
this.destroy()
|
|
306
|
-
}
|
|
307
|
-
})
|
|
308
|
-
.resume()
|
|
309
|
-
})
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
/**
|
|
313
|
-
* @param {BufferEncoding} encoding
|
|
314
|
-
* @returns {this}
|
|
315
|
-
*/
|
|
316
|
-
setEncoding (encoding) {
|
|
317
|
-
if (Buffer.isEncoding(encoding)) {
|
|
318
|
-
this._readableState.encoding = encoding
|
|
319
|
-
}
|
|
320
|
-
return this
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
/**
|
|
325
|
-
* @see https://streams.spec.whatwg.org/#readablestream-locked
|
|
326
|
-
* @param {BodyReadable} bodyReadable
|
|
327
|
-
* @returns {boolean}
|
|
328
|
-
*/
|
|
329
|
-
function isLocked (bodyReadable) {
|
|
330
|
-
// Consume is an implicit lock.
|
|
331
|
-
return bodyReadable[kBody]?.locked === true || bodyReadable[kConsume] !== null
|
|
332
|
-
}
|
|
333
|
-
|
|
334
|
-
/**
|
|
335
|
-
* @see https://fetch.spec.whatwg.org/#body-unusable
|
|
336
|
-
* @param {BodyReadable} bodyReadable
|
|
337
|
-
* @returns {boolean}
|
|
338
|
-
*/
|
|
339
|
-
function isUnusable (bodyReadable) {
|
|
340
|
-
return util.isDisturbed(bodyReadable) || isLocked(bodyReadable)
|
|
341
|
-
}
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* @typedef {object} Consume
|
|
345
|
-
* @property {string} type
|
|
346
|
-
* @property {BodyReadable} stream
|
|
347
|
-
* @property {((value?: any) => void)} resolve
|
|
348
|
-
* @property {((err: Error) => void)} reject
|
|
349
|
-
* @property {number} length
|
|
350
|
-
* @property {Buffer[]} body
|
|
351
|
-
*/
|
|
352
|
-
|
|
353
|
-
/**
|
|
354
|
-
* @param {BodyReadable} stream
|
|
355
|
-
* @param {string} type
|
|
356
|
-
* @returns {Promise<any>}
|
|
357
|
-
*/
|
|
358
|
-
function consume (stream, type) {
|
|
359
|
-
assert(!stream[kConsume])
|
|
360
|
-
|
|
361
|
-
return new Promise((resolve, reject) => {
|
|
362
|
-
if (isUnusable(stream)) {
|
|
363
|
-
const rState = stream._readableState
|
|
364
|
-
if (rState.destroyed && rState.closeEmitted === false) {
|
|
365
|
-
stream
|
|
366
|
-
.on('error', err => {
|
|
367
|
-
reject(err)
|
|
368
|
-
})
|
|
369
|
-
.on('close', () => {
|
|
370
|
-
reject(new TypeError('unusable'))
|
|
371
|
-
})
|
|
372
|
-
} else {
|
|
373
|
-
reject(rState.errored ?? new TypeError('unusable'))
|
|
374
|
-
}
|
|
375
|
-
} else {
|
|
376
|
-
queueMicrotask(() => {
|
|
377
|
-
stream[kConsume] = {
|
|
378
|
-
type,
|
|
379
|
-
stream,
|
|
380
|
-
resolve,
|
|
381
|
-
reject,
|
|
382
|
-
length: 0,
|
|
383
|
-
body: []
|
|
384
|
-
}
|
|
385
|
-
|
|
386
|
-
stream
|
|
387
|
-
.on('error', function (err) {
|
|
388
|
-
consumeFinish(this[kConsume], err)
|
|
389
|
-
})
|
|
390
|
-
.on('close', function () {
|
|
391
|
-
if (this[kConsume].body !== null) {
|
|
392
|
-
consumeFinish(this[kConsume], new RequestAbortedError())
|
|
393
|
-
}
|
|
394
|
-
})
|
|
395
|
-
|
|
396
|
-
consumeStart(stream[kConsume])
|
|
397
|
-
})
|
|
398
|
-
}
|
|
399
|
-
})
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
/**
|
|
403
|
-
* @param {Consume} consume
|
|
404
|
-
* @returns {void}
|
|
405
|
-
*/
|
|
406
|
-
function consumeStart (consume) {
|
|
407
|
-
if (consume.body === null) {
|
|
408
|
-
return
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
const { _readableState: state } = consume.stream
|
|
412
|
-
|
|
413
|
-
if (state.bufferIndex) {
|
|
414
|
-
const start = state.bufferIndex
|
|
415
|
-
const end = state.buffer.length
|
|
416
|
-
for (let n = start; n < end; n++) {
|
|
417
|
-
consumePush(consume, state.buffer[n])
|
|
418
|
-
}
|
|
419
|
-
} else {
|
|
420
|
-
for (const chunk of state.buffer) {
|
|
421
|
-
consumePush(consume, chunk)
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
if (state.endEmitted) {
|
|
426
|
-
consumeEnd(this[kConsume], this._readableState.encoding)
|
|
427
|
-
} else {
|
|
428
|
-
consume.stream.on('end', function () {
|
|
429
|
-
consumeEnd(this[kConsume], this._readableState.encoding)
|
|
430
|
-
})
|
|
431
|
-
}
|
|
432
|
-
|
|
433
|
-
consume.stream.resume()
|
|
434
|
-
|
|
435
|
-
while (consume.stream.read() != null) {
|
|
436
|
-
// Loop
|
|
437
|
-
}
|
|
438
|
-
}
|
|
439
|
-
|
|
440
|
-
/**
|
|
441
|
-
* @param {Buffer[]} chunks
|
|
442
|
-
* @param {number} length
|
|
443
|
-
* @param {BufferEncoding} encoding
|
|
444
|
-
* @returns {string}
|
|
445
|
-
*/
|
|
446
|
-
function chunksDecode (chunks, length, encoding) {
|
|
447
|
-
if (chunks.length === 0 || length === 0) {
|
|
448
|
-
return ''
|
|
449
|
-
}
|
|
450
|
-
const buffer = chunks.length === 1 ? chunks[0] : Buffer.concat(chunks, length)
|
|
451
|
-
const bufferLength = buffer.length
|
|
452
|
-
|
|
453
|
-
// Skip BOM.
|
|
454
|
-
const start =
|
|
455
|
-
bufferLength > 2 &&
|
|
456
|
-
buffer[0] === 0xef &&
|
|
457
|
-
buffer[1] === 0xbb &&
|
|
458
|
-
buffer[2] === 0xbf
|
|
459
|
-
? 3
|
|
460
|
-
: 0
|
|
461
|
-
if (!encoding || encoding === 'utf8' || encoding === 'utf-8') {
|
|
462
|
-
return buffer.utf8Slice(start, bufferLength)
|
|
463
|
-
} else {
|
|
464
|
-
return buffer.subarray(start, bufferLength).toString(encoding)
|
|
465
|
-
}
|
|
466
|
-
}
|
|
467
|
-
|
|
468
|
-
/**
|
|
469
|
-
* @param {Buffer[]} chunks
|
|
470
|
-
* @param {number} length
|
|
471
|
-
* @returns {Uint8Array}
|
|
472
|
-
*/
|
|
473
|
-
function chunksConcat (chunks, length) {
|
|
474
|
-
if (chunks.length === 0 || length === 0) {
|
|
475
|
-
return new Uint8Array(0)
|
|
476
|
-
}
|
|
477
|
-
if (chunks.length === 1) {
|
|
478
|
-
// fast-path
|
|
479
|
-
return new Uint8Array(chunks[0])
|
|
480
|
-
}
|
|
481
|
-
const buffer = new Uint8Array(Buffer.allocUnsafeSlow(length).buffer)
|
|
482
|
-
|
|
483
|
-
let offset = 0
|
|
484
|
-
for (let i = 0; i < chunks.length; ++i) {
|
|
485
|
-
const chunk = chunks[i]
|
|
486
|
-
buffer.set(chunk, offset)
|
|
487
|
-
offset += chunk.length
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
return buffer
|
|
491
|
-
}
|
|
492
|
-
|
|
493
|
-
/**
|
|
494
|
-
* @param {Consume} consume
|
|
495
|
-
* @param {BufferEncoding} encoding
|
|
496
|
-
* @returns {void}
|
|
497
|
-
*/
|
|
498
|
-
function consumeEnd (consume, encoding) {
|
|
499
|
-
const { type, body, resolve, stream, length } = consume
|
|
500
|
-
|
|
501
|
-
try {
|
|
502
|
-
if (type === 'text') {
|
|
503
|
-
resolve(chunksDecode(body, length, encoding))
|
|
504
|
-
} else if (type === 'json') {
|
|
505
|
-
resolve(JSON.parse(chunksDecode(body, length, encoding)))
|
|
506
|
-
} else if (type === 'arrayBuffer') {
|
|
507
|
-
resolve(chunksConcat(body, length).buffer)
|
|
508
|
-
} else if (type === 'blob') {
|
|
509
|
-
resolve(new Blob(body, { type: stream[kContentType] }))
|
|
510
|
-
} else if (type === 'bytes') {
|
|
511
|
-
resolve(chunksConcat(body, length))
|
|
512
|
-
}
|
|
513
|
-
|
|
514
|
-
consumeFinish(consume)
|
|
515
|
-
} catch (err) {
|
|
516
|
-
stream.destroy(err)
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
|
|
520
|
-
/**
|
|
521
|
-
* @param {Consume} consume
|
|
522
|
-
* @param {Buffer} chunk
|
|
523
|
-
* @returns {void}
|
|
524
|
-
*/
|
|
525
|
-
function consumePush (consume, chunk) {
|
|
526
|
-
consume.length += chunk.length
|
|
527
|
-
consume.body.push(chunk)
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
/**
|
|
531
|
-
* @param {Consume} consume
|
|
532
|
-
* @param {Error} [err]
|
|
533
|
-
* @returns {void}
|
|
534
|
-
*/
|
|
535
|
-
function consumeFinish (consume, err) {
|
|
536
|
-
if (consume.body === null) {
|
|
537
|
-
return
|
|
538
|
-
}
|
|
539
|
-
|
|
540
|
-
if (err) {
|
|
541
|
-
consume.reject(err)
|
|
542
|
-
} else {
|
|
543
|
-
consume.resolve()
|
|
544
|
-
}
|
|
545
|
-
|
|
546
|
-
// Reset the consume object to allow for garbage collection.
|
|
547
|
-
consume.type = null
|
|
548
|
-
consume.stream = null
|
|
549
|
-
consume.resolve = null
|
|
550
|
-
consume.reject = null
|
|
551
|
-
consume.length = 0
|
|
552
|
-
consume.body = null
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
module.exports = {
|
|
556
|
-
Readable: BodyReadable,
|
|
557
|
-
chunksDecode
|
|
558
|
-
}
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
'use strict'
|
|
2
|
-
|
|
3
|
-
const assert = require('node:assert')
|
|
4
|
-
const {
|
|
5
|
-
ResponseStatusCodeError
|
|
6
|
-
} = require('../core/errors')
|
|
7
|
-
|
|
8
|
-
const { chunksDecode } = require('./readable')
|
|
9
|
-
const CHUNK_LIMIT = 128 * 1024
|
|
10
|
-
|
|
11
|
-
async function getResolveErrorBodyCallback ({ callback, body, contentType, statusCode, statusMessage, headers }) {
|
|
12
|
-
assert(body)
|
|
13
|
-
|
|
14
|
-
let chunks = []
|
|
15
|
-
let length = 0
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
for await (const chunk of body) {
|
|
19
|
-
chunks.push(chunk)
|
|
20
|
-
length += chunk.length
|
|
21
|
-
if (length > CHUNK_LIMIT) {
|
|
22
|
-
chunks = []
|
|
23
|
-
length = 0
|
|
24
|
-
break
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
} catch {
|
|
28
|
-
chunks = []
|
|
29
|
-
length = 0
|
|
30
|
-
// Do nothing....
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
const message = `Response status code ${statusCode}${statusMessage ? `: ${statusMessage}` : ''}`
|
|
34
|
-
|
|
35
|
-
if (statusCode === 204 || !contentType || !length) {
|
|
36
|
-
queueMicrotask(() => callback(new ResponseStatusCodeError(message, statusCode, headers)))
|
|
37
|
-
return
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const stackTraceLimit = Error.stackTraceLimit
|
|
41
|
-
Error.stackTraceLimit = 0
|
|
42
|
-
let payload
|
|
43
|
-
|
|
44
|
-
try {
|
|
45
|
-
if (isContentTypeApplicationJson(contentType)) {
|
|
46
|
-
payload = JSON.parse(chunksDecode(chunks, length))
|
|
47
|
-
} else if (isContentTypeText(contentType)) {
|
|
48
|
-
payload = chunksDecode(chunks, length)
|
|
49
|
-
}
|
|
50
|
-
} catch {
|
|
51
|
-
// process in a callback to avoid throwing in the microtask queue
|
|
52
|
-
} finally {
|
|
53
|
-
Error.stackTraceLimit = stackTraceLimit
|
|
54
|
-
}
|
|
55
|
-
queueMicrotask(() => callback(new ResponseStatusCodeError(message, statusCode, headers, payload)))
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const isContentTypeApplicationJson = (contentType) => {
|
|
59
|
-
return (
|
|
60
|
-
contentType.length > 15 &&
|
|
61
|
-
contentType[11] === '/' &&
|
|
62
|
-
contentType[0] === 'a' &&
|
|
63
|
-
contentType[1] === 'p' &&
|
|
64
|
-
contentType[2] === 'p' &&
|
|
65
|
-
contentType[3] === 'l' &&
|
|
66
|
-
contentType[4] === 'i' &&
|
|
67
|
-
contentType[5] === 'c' &&
|
|
68
|
-
contentType[6] === 'a' &&
|
|
69
|
-
contentType[7] === 't' &&
|
|
70
|
-
contentType[8] === 'i' &&
|
|
71
|
-
contentType[9] === 'o' &&
|
|
72
|
-
contentType[10] === 'n' &&
|
|
73
|
-
contentType[12] === 'j' &&
|
|
74
|
-
contentType[13] === 's' &&
|
|
75
|
-
contentType[14] === 'o' &&
|
|
76
|
-
contentType[15] === 'n'
|
|
77
|
-
)
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
const isContentTypeText = (contentType) => {
|
|
81
|
-
return (
|
|
82
|
-
contentType.length > 4 &&
|
|
83
|
-
contentType[4] === '/' &&
|
|
84
|
-
contentType[0] === 't' &&
|
|
85
|
-
contentType[1] === 'e' &&
|
|
86
|
-
contentType[2] === 'x' &&
|
|
87
|
-
contentType[3] === 't'
|
|
88
|
-
)
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
module.exports = {
|
|
92
|
-
getResolveErrorBodyCallback,
|
|
93
|
-
isContentTypeApplicationJson,
|
|
94
|
-
isContentTypeText
|
|
95
|
-
}
|