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.
Files changed (193) hide show
  1. package/bundle/dvcode.js +757 -753
  2. package/package.json +1 -1
  3. package/bundle/assets/help/README.md +0 -113
  4. package/bundle/assets/sounds/README.md +0 -74
  5. package/bundle/node_modules/undici/LICENSE +0 -21
  6. package/bundle/node_modules/undici/README.md +0 -472
  7. package/bundle/node_modules/undici/docs/docs/api/Agent.md +0 -83
  8. package/bundle/node_modules/undici/docs/docs/api/BalancedPool.md +0 -99
  9. package/bundle/node_modules/undici/docs/docs/api/CacheStorage.md +0 -30
  10. package/bundle/node_modules/undici/docs/docs/api/CacheStore.md +0 -151
  11. package/bundle/node_modules/undici/docs/docs/api/Client.md +0 -281
  12. package/bundle/node_modules/undici/docs/docs/api/ClientStats.md +0 -27
  13. package/bundle/node_modules/undici/docs/docs/api/Connector.md +0 -115
  14. package/bundle/node_modules/undici/docs/docs/api/ContentType.md +0 -57
  15. package/bundle/node_modules/undici/docs/docs/api/Cookies.md +0 -101
  16. package/bundle/node_modules/undici/docs/docs/api/Debug.md +0 -62
  17. package/bundle/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +0 -204
  18. package/bundle/node_modules/undici/docs/docs/api/Dispatcher.md +0 -1200
  19. package/bundle/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +0 -159
  20. package/bundle/node_modules/undici/docs/docs/api/Errors.md +0 -49
  21. package/bundle/node_modules/undici/docs/docs/api/EventSource.md +0 -45
  22. package/bundle/node_modules/undici/docs/docs/api/Fetch.md +0 -52
  23. package/bundle/node_modules/undici/docs/docs/api/H2CClient.md +0 -262
  24. package/bundle/node_modules/undici/docs/docs/api/MockAgent.md +0 -603
  25. package/bundle/node_modules/undici/docs/docs/api/MockCallHistory.md +0 -197
  26. package/bundle/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +0 -43
  27. package/bundle/node_modules/undici/docs/docs/api/MockClient.md +0 -77
  28. package/bundle/node_modules/undici/docs/docs/api/MockErrors.md +0 -12
  29. package/bundle/node_modules/undici/docs/docs/api/MockPool.md +0 -548
  30. package/bundle/node_modules/undici/docs/docs/api/Pool.md +0 -84
  31. package/bundle/node_modules/undici/docs/docs/api/PoolStats.md +0 -35
  32. package/bundle/node_modules/undici/docs/docs/api/ProxyAgent.md +0 -227
  33. package/bundle/node_modules/undici/docs/docs/api/RedirectHandler.md +0 -96
  34. package/bundle/node_modules/undici/docs/docs/api/RetryAgent.md +0 -45
  35. package/bundle/node_modules/undici/docs/docs/api/RetryHandler.md +0 -117
  36. package/bundle/node_modules/undici/docs/docs/api/Util.md +0 -25
  37. package/bundle/node_modules/undici/docs/docs/api/WebSocket.md +0 -85
  38. package/bundle/node_modules/undici/docs/docs/api/api-lifecycle.md +0 -91
  39. package/bundle/node_modules/undici/docs/docs/best-practices/client-certificate.md +0 -64
  40. package/bundle/node_modules/undici/docs/docs/best-practices/mocking-request.md +0 -190
  41. package/bundle/node_modules/undici/docs/docs/best-practices/proxy.md +0 -127
  42. package/bundle/node_modules/undici/docs/docs/best-practices/writing-tests.md +0 -20
  43. package/bundle/node_modules/undici/index-fetch.js +0 -35
  44. package/bundle/node_modules/undici/index.d.ts +0 -3
  45. package/bundle/node_modules/undici/index.js +0 -183
  46. package/bundle/node_modules/undici/lib/api/abort-signal.js +0 -59
  47. package/bundle/node_modules/undici/lib/api/api-connect.js +0 -110
  48. package/bundle/node_modules/undici/lib/api/api-pipeline.js +0 -252
  49. package/bundle/node_modules/undici/lib/api/api-request.js +0 -199
  50. package/bundle/node_modules/undici/lib/api/api-stream.js +0 -209
  51. package/bundle/node_modules/undici/lib/api/api-upgrade.js +0 -110
  52. package/bundle/node_modules/undici/lib/api/index.js +0 -7
  53. package/bundle/node_modules/undici/lib/api/readable.js +0 -558
  54. package/bundle/node_modules/undici/lib/api/util.js +0 -95
  55. package/bundle/node_modules/undici/lib/cache/memory-cache-store.js +0 -234
  56. package/bundle/node_modules/undici/lib/cache/sqlite-cache-store.js +0 -461
  57. package/bundle/node_modules/undici/lib/core/connect.js +0 -164
  58. package/bundle/node_modules/undici/lib/core/constants.js +0 -143
  59. package/bundle/node_modules/undici/lib/core/diagnostics.js +0 -196
  60. package/bundle/node_modules/undici/lib/core/errors.js +0 -244
  61. package/bundle/node_modules/undici/lib/core/request.js +0 -397
  62. package/bundle/node_modules/undici/lib/core/symbols.js +0 -68
  63. package/bundle/node_modules/undici/lib/core/tree.js +0 -160
  64. package/bundle/node_modules/undici/lib/core/util.js +0 -988
  65. package/bundle/node_modules/undici/lib/dispatcher/agent.js +0 -135
  66. package/bundle/node_modules/undici/lib/dispatcher/balanced-pool.js +0 -206
  67. package/bundle/node_modules/undici/lib/dispatcher/client-h1.js +0 -1615
  68. package/bundle/node_modules/undici/lib/dispatcher/client-h2.js +0 -798
  69. package/bundle/node_modules/undici/lib/dispatcher/client.js +0 -614
  70. package/bundle/node_modules/undici/lib/dispatcher/dispatcher-base.js +0 -161
  71. package/bundle/node_modules/undici/lib/dispatcher/dispatcher.js +0 -48
  72. package/bundle/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +0 -151
  73. package/bundle/node_modules/undici/lib/dispatcher/fixed-queue.js +0 -159
  74. package/bundle/node_modules/undici/lib/dispatcher/h2c-client.js +0 -122
  75. package/bundle/node_modules/undici/lib/dispatcher/pool-base.js +0 -191
  76. package/bundle/node_modules/undici/lib/dispatcher/pool.js +0 -118
  77. package/bundle/node_modules/undici/lib/dispatcher/proxy-agent.js +0 -275
  78. package/bundle/node_modules/undici/lib/dispatcher/retry-agent.js +0 -35
  79. package/bundle/node_modules/undici/lib/global.js +0 -32
  80. package/bundle/node_modules/undici/lib/handler/cache-handler.js +0 -448
  81. package/bundle/node_modules/undici/lib/handler/cache-revalidation-handler.js +0 -124
  82. package/bundle/node_modules/undici/lib/handler/decorator-handler.js +0 -67
  83. package/bundle/node_modules/undici/lib/handler/redirect-handler.js +0 -227
  84. package/bundle/node_modules/undici/lib/handler/retry-handler.js +0 -342
  85. package/bundle/node_modules/undici/lib/handler/unwrap-handler.js +0 -96
  86. package/bundle/node_modules/undici/lib/handler/wrap-handler.js +0 -95
  87. package/bundle/node_modules/undici/lib/interceptor/cache.js +0 -372
  88. package/bundle/node_modules/undici/lib/interceptor/dns.js +0 -432
  89. package/bundle/node_modules/undici/lib/interceptor/dump.js +0 -111
  90. package/bundle/node_modules/undici/lib/interceptor/redirect.js +0 -21
  91. package/bundle/node_modules/undici/lib/interceptor/response-error.js +0 -95
  92. package/bundle/node_modules/undici/lib/interceptor/retry.js +0 -19
  93. package/bundle/node_modules/undici/lib/llhttp/.gitkeep +0 -0
  94. package/bundle/node_modules/undici/lib/llhttp/constants.d.ts +0 -97
  95. package/bundle/node_modules/undici/lib/llhttp/constants.js +0 -498
  96. package/bundle/node_modules/undici/lib/llhttp/constants.js.map +0 -1
  97. package/bundle/node_modules/undici/lib/llhttp/llhttp-wasm.js +0 -15
  98. package/bundle/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +0 -15
  99. package/bundle/node_modules/undici/lib/llhttp/utils.d.ts +0 -2
  100. package/bundle/node_modules/undici/lib/llhttp/utils.js +0 -15
  101. package/bundle/node_modules/undici/lib/llhttp/utils.js.map +0 -1
  102. package/bundle/node_modules/undici/lib/mock/mock-agent.js +0 -224
  103. package/bundle/node_modules/undici/lib/mock/mock-call-history.js +0 -248
  104. package/bundle/node_modules/undici/lib/mock/mock-client.js +0 -64
  105. package/bundle/node_modules/undici/lib/mock/mock-errors.js +0 -19
  106. package/bundle/node_modules/undici/lib/mock/mock-interceptor.js +0 -209
  107. package/bundle/node_modules/undici/lib/mock/mock-pool.js +0 -64
  108. package/bundle/node_modules/undici/lib/mock/mock-symbols.js +0 -31
  109. package/bundle/node_modules/undici/lib/mock/mock-utils.js +0 -433
  110. package/bundle/node_modules/undici/lib/mock/pending-interceptors-formatter.js +0 -43
  111. package/bundle/node_modules/undici/lib/util/cache.js +0 -368
  112. package/bundle/node_modules/undici/lib/util/date.js +0 -259
  113. package/bundle/node_modules/undici/lib/util/stats.js +0 -32
  114. package/bundle/node_modules/undici/lib/util/timers.js +0 -423
  115. package/bundle/node_modules/undici/lib/web/cache/cache.js +0 -862
  116. package/bundle/node_modules/undici/lib/web/cache/cachestorage.js +0 -152
  117. package/bundle/node_modules/undici/lib/web/cache/util.js +0 -45
  118. package/bundle/node_modules/undici/lib/web/cookies/constants.js +0 -12
  119. package/bundle/node_modules/undici/lib/web/cookies/index.js +0 -199
  120. package/bundle/node_modules/undici/lib/web/cookies/parse.js +0 -322
  121. package/bundle/node_modules/undici/lib/web/cookies/util.js +0 -282
  122. package/bundle/node_modules/undici/lib/web/eventsource/eventsource-stream.js +0 -399
  123. package/bundle/node_modules/undici/lib/web/eventsource/eventsource.js +0 -484
  124. package/bundle/node_modules/undici/lib/web/eventsource/util.js +0 -37
  125. package/bundle/node_modules/undici/lib/web/fetch/LICENSE +0 -21
  126. package/bundle/node_modules/undici/lib/web/fetch/body.js +0 -532
  127. package/bundle/node_modules/undici/lib/web/fetch/constants.js +0 -131
  128. package/bundle/node_modules/undici/lib/web/fetch/data-url.js +0 -744
  129. package/bundle/node_modules/undici/lib/web/fetch/dispatcher-weakref.js +0 -46
  130. package/bundle/node_modules/undici/lib/web/fetch/formdata-parser.js +0 -501
  131. package/bundle/node_modules/undici/lib/web/fetch/formdata.js +0 -263
  132. package/bundle/node_modules/undici/lib/web/fetch/global.js +0 -40
  133. package/bundle/node_modules/undici/lib/web/fetch/headers.js +0 -719
  134. package/bundle/node_modules/undici/lib/web/fetch/index.js +0 -2258
  135. package/bundle/node_modules/undici/lib/web/fetch/request.js +0 -1099
  136. package/bundle/node_modules/undici/lib/web/fetch/response.js +0 -636
  137. package/bundle/node_modules/undici/lib/web/fetch/util.js +0 -1782
  138. package/bundle/node_modules/undici/lib/web/fetch/webidl.js +0 -740
  139. package/bundle/node_modules/undici/lib/web/websocket/connection.js +0 -325
  140. package/bundle/node_modules/undici/lib/web/websocket/constants.js +0 -126
  141. package/bundle/node_modules/undici/lib/web/websocket/events.js +0 -331
  142. package/bundle/node_modules/undici/lib/web/websocket/frame.js +0 -138
  143. package/bundle/node_modules/undici/lib/web/websocket/permessage-deflate.js +0 -70
  144. package/bundle/node_modules/undici/lib/web/websocket/receiver.js +0 -454
  145. package/bundle/node_modules/undici/lib/web/websocket/sender.js +0 -109
  146. package/bundle/node_modules/undici/lib/web/websocket/stream/websocketerror.js +0 -83
  147. package/bundle/node_modules/undici/lib/web/websocket/stream/websocketstream.js +0 -485
  148. package/bundle/node_modules/undici/lib/web/websocket/util.js +0 -338
  149. package/bundle/node_modules/undici/lib/web/websocket/websocket.js +0 -686
  150. package/bundle/node_modules/undici/package.json +0 -149
  151. package/bundle/node_modules/undici/scripts/strip-comments.js +0 -10
  152. package/bundle/node_modules/undici/types/README.md +0 -6
  153. package/bundle/node_modules/undici/types/agent.d.ts +0 -35
  154. package/bundle/node_modules/undici/types/api.d.ts +0 -43
  155. package/bundle/node_modules/undici/types/balanced-pool.d.ts +0 -29
  156. package/bundle/node_modules/undici/types/cache-interceptor.d.ts +0 -172
  157. package/bundle/node_modules/undici/types/cache.d.ts +0 -36
  158. package/bundle/node_modules/undici/types/client-stats.d.ts +0 -15
  159. package/bundle/node_modules/undici/types/client.d.ts +0 -110
  160. package/bundle/node_modules/undici/types/connector.d.ts +0 -34
  161. package/bundle/node_modules/undici/types/content-type.d.ts +0 -21
  162. package/bundle/node_modules/undici/types/cookies.d.ts +0 -30
  163. package/bundle/node_modules/undici/types/diagnostics-channel.d.ts +0 -66
  164. package/bundle/node_modules/undici/types/dispatcher.d.ts +0 -281
  165. package/bundle/node_modules/undici/types/env-http-proxy-agent.d.ts +0 -21
  166. package/bundle/node_modules/undici/types/errors.d.ts +0 -171
  167. package/bundle/node_modules/undici/types/eventsource.d.ts +0 -61
  168. package/bundle/node_modules/undici/types/fetch.d.ts +0 -210
  169. package/bundle/node_modules/undici/types/formdata.d.ts +0 -108
  170. package/bundle/node_modules/undici/types/global-dispatcher.d.ts +0 -9
  171. package/bundle/node_modules/undici/types/global-origin.d.ts +0 -7
  172. package/bundle/node_modules/undici/types/h2c-client.d.ts +0 -75
  173. package/bundle/node_modules/undici/types/handlers.d.ts +0 -15
  174. package/bundle/node_modules/undici/types/header.d.ts +0 -160
  175. package/bundle/node_modules/undici/types/index.d.ts +0 -75
  176. package/bundle/node_modules/undici/types/interceptors.d.ts +0 -34
  177. package/bundle/node_modules/undici/types/mock-agent.d.ts +0 -68
  178. package/bundle/node_modules/undici/types/mock-call-history.d.ts +0 -111
  179. package/bundle/node_modules/undici/types/mock-client.d.ts +0 -25
  180. package/bundle/node_modules/undici/types/mock-errors.d.ts +0 -12
  181. package/bundle/node_modules/undici/types/mock-interceptor.d.ts +0 -93
  182. package/bundle/node_modules/undici/types/mock-pool.d.ts +0 -25
  183. package/bundle/node_modules/undici/types/patch.d.ts +0 -29
  184. package/bundle/node_modules/undici/types/pool-stats.d.ts +0 -19
  185. package/bundle/node_modules/undici/types/pool.d.ts +0 -41
  186. package/bundle/node_modules/undici/types/proxy-agent.d.ts +0 -29
  187. package/bundle/node_modules/undici/types/readable.d.ts +0 -68
  188. package/bundle/node_modules/undici/types/retry-agent.d.ts +0 -8
  189. package/bundle/node_modules/undici/types/retry-handler.d.ts +0 -116
  190. package/bundle/node_modules/undici/types/util.d.ts +0 -18
  191. package/bundle/node_modules/undici/types/utility.d.ts +0 -7
  192. package/bundle/node_modules/undici/types/webidl.d.ts +0 -266
  193. package/bundle/node_modules/undici/types/websocket.d.ts +0 -184
@@ -1,614 +0,0 @@
1
- 'use strict'
2
-
3
- const assert = require('node:assert')
4
- const net = require('node:net')
5
- const http = require('node:http')
6
- const util = require('../core/util.js')
7
- const { ClientStats } = require('../util/stats.js')
8
- const { channels } = require('../core/diagnostics.js')
9
- const Request = require('../core/request.js')
10
- const DispatcherBase = require('./dispatcher-base')
11
- const {
12
- InvalidArgumentError,
13
- InformationalError,
14
- ClientDestroyedError
15
- } = require('../core/errors.js')
16
- const buildConnector = require('../core/connect.js')
17
- const {
18
- kUrl,
19
- kServerName,
20
- kClient,
21
- kBusy,
22
- kConnect,
23
- kResuming,
24
- kRunning,
25
- kPending,
26
- kSize,
27
- kQueue,
28
- kConnected,
29
- kConnecting,
30
- kNeedDrain,
31
- kKeepAliveDefaultTimeout,
32
- kHostHeader,
33
- kPendingIdx,
34
- kRunningIdx,
35
- kError,
36
- kPipelining,
37
- kKeepAliveTimeoutValue,
38
- kMaxHeadersSize,
39
- kKeepAliveMaxTimeout,
40
- kKeepAliveTimeoutThreshold,
41
- kHeadersTimeout,
42
- kBodyTimeout,
43
- kStrictContentLength,
44
- kConnector,
45
- kMaxRequests,
46
- kCounter,
47
- kClose,
48
- kDestroy,
49
- kDispatch,
50
- kLocalAddress,
51
- kMaxResponseSize,
52
- kOnError,
53
- kHTTPContext,
54
- kMaxConcurrentStreams,
55
- kResume
56
- } = require('../core/symbols.js')
57
- const connectH1 = require('./client-h1.js')
58
- const connectH2 = require('./client-h2.js')
59
-
60
- const kClosedResolve = Symbol('kClosedResolve')
61
-
62
- const getDefaultNodeMaxHeaderSize = http &&
63
- http.maxHeaderSize &&
64
- Number.isInteger(http.maxHeaderSize) &&
65
- http.maxHeaderSize > 0
66
- ? () => http.maxHeaderSize
67
- : () => { throw new InvalidArgumentError('http module not available or http.maxHeaderSize invalid') }
68
-
69
- const noop = () => {}
70
-
71
- function getPipelining (client) {
72
- return client[kPipelining] ?? client[kHTTPContext]?.defaultPipelining ?? 1
73
- }
74
-
75
- /**
76
- * @type {import('../../types/client.js').default}
77
- */
78
- class Client extends DispatcherBase {
79
- /**
80
- *
81
- * @param {string|URL} url
82
- * @param {import('../../types/client.js').Client.Options} options
83
- */
84
- constructor (url, {
85
- maxHeaderSize,
86
- headersTimeout,
87
- socketTimeout,
88
- requestTimeout,
89
- connectTimeout,
90
- bodyTimeout,
91
- idleTimeout,
92
- keepAlive,
93
- keepAliveTimeout,
94
- maxKeepAliveTimeout,
95
- keepAliveMaxTimeout,
96
- keepAliveTimeoutThreshold,
97
- socketPath,
98
- pipelining,
99
- tls,
100
- strictContentLength,
101
- maxCachedSessions,
102
- connect,
103
- maxRequestsPerClient,
104
- localAddress,
105
- maxResponseSize,
106
- autoSelectFamily,
107
- autoSelectFamilyAttemptTimeout,
108
- // h2
109
- maxConcurrentStreams,
110
- allowH2
111
- } = {}) {
112
- if (keepAlive !== undefined) {
113
- throw new InvalidArgumentError('unsupported keepAlive, use pipelining=0 instead')
114
- }
115
-
116
- if (socketTimeout !== undefined) {
117
- throw new InvalidArgumentError('unsupported socketTimeout, use headersTimeout & bodyTimeout instead')
118
- }
119
-
120
- if (requestTimeout !== undefined) {
121
- throw new InvalidArgumentError('unsupported requestTimeout, use headersTimeout & bodyTimeout instead')
122
- }
123
-
124
- if (idleTimeout !== undefined) {
125
- throw new InvalidArgumentError('unsupported idleTimeout, use keepAliveTimeout instead')
126
- }
127
-
128
- if (maxKeepAliveTimeout !== undefined) {
129
- throw new InvalidArgumentError('unsupported maxKeepAliveTimeout, use keepAliveMaxTimeout instead')
130
- }
131
-
132
- if (maxHeaderSize != null) {
133
- if (!Number.isInteger(maxHeaderSize) || maxHeaderSize < 1) {
134
- throw new InvalidArgumentError('invalid maxHeaderSize')
135
- }
136
- } else {
137
- // If maxHeaderSize is not provided, use the default value from the http module
138
- // or if that is not available, throw an error.
139
- maxHeaderSize = getDefaultNodeMaxHeaderSize()
140
- }
141
-
142
- if (socketPath != null && typeof socketPath !== 'string') {
143
- throw new InvalidArgumentError('invalid socketPath')
144
- }
145
-
146
- if (connectTimeout != null && (!Number.isFinite(connectTimeout) || connectTimeout < 0)) {
147
- throw new InvalidArgumentError('invalid connectTimeout')
148
- }
149
-
150
- if (keepAliveTimeout != null && (!Number.isFinite(keepAliveTimeout) || keepAliveTimeout <= 0)) {
151
- throw new InvalidArgumentError('invalid keepAliveTimeout')
152
- }
153
-
154
- if (keepAliveMaxTimeout != null && (!Number.isFinite(keepAliveMaxTimeout) || keepAliveMaxTimeout <= 0)) {
155
- throw new InvalidArgumentError('invalid keepAliveMaxTimeout')
156
- }
157
-
158
- if (keepAliveTimeoutThreshold != null && !Number.isFinite(keepAliveTimeoutThreshold)) {
159
- throw new InvalidArgumentError('invalid keepAliveTimeoutThreshold')
160
- }
161
-
162
- if (headersTimeout != null && (!Number.isInteger(headersTimeout) || headersTimeout < 0)) {
163
- throw new InvalidArgumentError('headersTimeout must be a positive integer or zero')
164
- }
165
-
166
- if (bodyTimeout != null && (!Number.isInteger(bodyTimeout) || bodyTimeout < 0)) {
167
- throw new InvalidArgumentError('bodyTimeout must be a positive integer or zero')
168
- }
169
-
170
- if (connect != null && typeof connect !== 'function' && typeof connect !== 'object') {
171
- throw new InvalidArgumentError('connect must be a function or an object')
172
- }
173
-
174
- if (maxRequestsPerClient != null && (!Number.isInteger(maxRequestsPerClient) || maxRequestsPerClient < 0)) {
175
- throw new InvalidArgumentError('maxRequestsPerClient must be a positive number')
176
- }
177
-
178
- if (localAddress != null && (typeof localAddress !== 'string' || net.isIP(localAddress) === 0)) {
179
- throw new InvalidArgumentError('localAddress must be valid string IP address')
180
- }
181
-
182
- if (maxResponseSize != null && (!Number.isInteger(maxResponseSize) || maxResponseSize < -1)) {
183
- throw new InvalidArgumentError('maxResponseSize must be a positive number')
184
- }
185
-
186
- if (
187
- autoSelectFamilyAttemptTimeout != null &&
188
- (!Number.isInteger(autoSelectFamilyAttemptTimeout) || autoSelectFamilyAttemptTimeout < -1)
189
- ) {
190
- throw new InvalidArgumentError('autoSelectFamilyAttemptTimeout must be a positive number')
191
- }
192
-
193
- // h2
194
- if (allowH2 != null && typeof allowH2 !== 'boolean') {
195
- throw new InvalidArgumentError('allowH2 must be a valid boolean value')
196
- }
197
-
198
- if (maxConcurrentStreams != null && (typeof maxConcurrentStreams !== 'number' || maxConcurrentStreams < 1)) {
199
- throw new InvalidArgumentError('maxConcurrentStreams must be a positive integer, greater than 0')
200
- }
201
-
202
- super()
203
-
204
- if (typeof connect !== 'function') {
205
- connect = buildConnector({
206
- ...tls,
207
- maxCachedSessions,
208
- allowH2,
209
- socketPath,
210
- timeout: connectTimeout,
211
- ...(typeof autoSelectFamily === 'boolean' ? { autoSelectFamily, autoSelectFamilyAttemptTimeout } : undefined),
212
- ...connect
213
- })
214
- }
215
-
216
- this[kUrl] = util.parseOrigin(url)
217
- this[kConnector] = connect
218
- this[kPipelining] = pipelining != null ? pipelining : 1
219
- this[kMaxHeadersSize] = maxHeaderSize
220
- this[kKeepAliveDefaultTimeout] = keepAliveTimeout == null ? 4e3 : keepAliveTimeout
221
- this[kKeepAliveMaxTimeout] = keepAliveMaxTimeout == null ? 600e3 : keepAliveMaxTimeout
222
- this[kKeepAliveTimeoutThreshold] = keepAliveTimeoutThreshold == null ? 2e3 : keepAliveTimeoutThreshold
223
- this[kKeepAliveTimeoutValue] = this[kKeepAliveDefaultTimeout]
224
- this[kServerName] = null
225
- this[kLocalAddress] = localAddress != null ? localAddress : null
226
- this[kResuming] = 0 // 0, idle, 1, scheduled, 2 resuming
227
- this[kNeedDrain] = 0 // 0, idle, 1, scheduled, 2 resuming
228
- this[kHostHeader] = `host: ${this[kUrl].hostname}${this[kUrl].port ? `:${this[kUrl].port}` : ''}\r\n`
229
- this[kBodyTimeout] = bodyTimeout != null ? bodyTimeout : 300e3
230
- this[kHeadersTimeout] = headersTimeout != null ? headersTimeout : 300e3
231
- this[kStrictContentLength] = strictContentLength == null ? true : strictContentLength
232
- this[kMaxRequests] = maxRequestsPerClient
233
- this[kClosedResolve] = null
234
- this[kMaxResponseSize] = maxResponseSize > -1 ? maxResponseSize : -1
235
- this[kMaxConcurrentStreams] = maxConcurrentStreams != null ? maxConcurrentStreams : 100 // Max peerConcurrentStreams for a Node h2 server
236
- this[kHTTPContext] = null
237
-
238
- // kQueue is built up of 3 sections separated by
239
- // the kRunningIdx and kPendingIdx indices.
240
- // | complete | running | pending |
241
- // ^ kRunningIdx ^ kPendingIdx ^ kQueue.length
242
- // kRunningIdx points to the first running element.
243
- // kPendingIdx points to the first pending element.
244
- // This implements a fast queue with an amortized
245
- // time of O(1).
246
-
247
- this[kQueue] = []
248
- this[kRunningIdx] = 0
249
- this[kPendingIdx] = 0
250
-
251
- this[kResume] = (sync) => resume(this, sync)
252
- this[kOnError] = (err) => onError(this, err)
253
- }
254
-
255
- get pipelining () {
256
- return this[kPipelining]
257
- }
258
-
259
- set pipelining (value) {
260
- this[kPipelining] = value
261
- this[kResume](true)
262
- }
263
-
264
- get stats () {
265
- return new ClientStats(this)
266
- }
267
-
268
- get [kPending] () {
269
- return this[kQueue].length - this[kPendingIdx]
270
- }
271
-
272
- get [kRunning] () {
273
- return this[kPendingIdx] - this[kRunningIdx]
274
- }
275
-
276
- get [kSize] () {
277
- return this[kQueue].length - this[kRunningIdx]
278
- }
279
-
280
- get [kConnected] () {
281
- return !!this[kHTTPContext] && !this[kConnecting] && !this[kHTTPContext].destroyed
282
- }
283
-
284
- get [kBusy] () {
285
- return Boolean(
286
- this[kHTTPContext]?.busy(null) ||
287
- (this[kSize] >= (getPipelining(this) || 1)) ||
288
- this[kPending] > 0
289
- )
290
- }
291
-
292
- /* istanbul ignore: only used for test */
293
- [kConnect] (cb) {
294
- connect(this)
295
- this.once('connect', cb)
296
- }
297
-
298
- [kDispatch] (opts, handler) {
299
- const origin = opts.origin || this[kUrl].origin
300
- const request = new Request(origin, opts, handler)
301
-
302
- this[kQueue].push(request)
303
- if (this[kResuming]) {
304
- // Do nothing.
305
- } else if (util.bodyLength(request.body) == null && util.isIterable(request.body)) {
306
- // Wait a tick in case stream/iterator is ended in the same tick.
307
- this[kResuming] = 1
308
- queueMicrotask(() => resume(this))
309
- } else {
310
- this[kResume](true)
311
- }
312
-
313
- if (this[kResuming] && this[kNeedDrain] !== 2 && this[kBusy]) {
314
- this[kNeedDrain] = 2
315
- }
316
-
317
- return this[kNeedDrain] < 2
318
- }
319
-
320
- async [kClose] () {
321
- // TODO: for H2 we need to gracefully flush the remaining enqueued
322
- // request and close each stream.
323
- return new Promise((resolve) => {
324
- if (this[kSize]) {
325
- this[kClosedResolve] = resolve
326
- } else {
327
- resolve(null)
328
- }
329
- })
330
- }
331
-
332
- async [kDestroy] (err) {
333
- return new Promise((resolve) => {
334
- const requests = this[kQueue].splice(this[kPendingIdx])
335
- for (let i = 0; i < requests.length; i++) {
336
- const request = requests[i]
337
- util.errorRequest(this, request, err)
338
- }
339
-
340
- const callback = () => {
341
- if (this[kClosedResolve]) {
342
- // TODO (fix): Should we error here with ClientDestroyedError?
343
- this[kClosedResolve]()
344
- this[kClosedResolve] = null
345
- }
346
- resolve(null)
347
- }
348
-
349
- if (this[kHTTPContext]) {
350
- this[kHTTPContext].destroy(err, callback)
351
- this[kHTTPContext] = null
352
- } else {
353
- queueMicrotask(callback)
354
- }
355
-
356
- this[kResume]()
357
- })
358
- }
359
- }
360
-
361
- function onError (client, err) {
362
- if (
363
- client[kRunning] === 0 &&
364
- err.code !== 'UND_ERR_INFO' &&
365
- err.code !== 'UND_ERR_SOCKET'
366
- ) {
367
- // Error is not caused by running request and not a recoverable
368
- // socket error.
369
-
370
- assert(client[kPendingIdx] === client[kRunningIdx])
371
-
372
- const requests = client[kQueue].splice(client[kRunningIdx])
373
-
374
- for (let i = 0; i < requests.length; i++) {
375
- const request = requests[i]
376
- util.errorRequest(client, request, err)
377
- }
378
- assert(client[kSize] === 0)
379
- }
380
- }
381
-
382
- /**
383
- * @param {Client} client
384
- * @returns
385
- */
386
- async function connect (client) {
387
- assert(!client[kConnecting])
388
- assert(!client[kHTTPContext])
389
-
390
- let { host, hostname, protocol, port } = client[kUrl]
391
-
392
- // Resolve ipv6
393
- if (hostname[0] === '[') {
394
- const idx = hostname.indexOf(']')
395
-
396
- assert(idx !== -1)
397
- const ip = hostname.substring(1, idx)
398
-
399
- assert(net.isIPv6(ip))
400
- hostname = ip
401
- }
402
-
403
- client[kConnecting] = true
404
-
405
- if (channels.beforeConnect.hasSubscribers) {
406
- channels.beforeConnect.publish({
407
- connectParams: {
408
- host,
409
- hostname,
410
- protocol,
411
- port,
412
- version: client[kHTTPContext]?.version,
413
- servername: client[kServerName],
414
- localAddress: client[kLocalAddress]
415
- },
416
- connector: client[kConnector]
417
- })
418
- }
419
-
420
- try {
421
- const socket = await new Promise((resolve, reject) => {
422
- client[kConnector]({
423
- host,
424
- hostname,
425
- protocol,
426
- port,
427
- servername: client[kServerName],
428
- localAddress: client[kLocalAddress]
429
- }, (err, socket) => {
430
- if (err) {
431
- reject(err)
432
- } else {
433
- resolve(socket)
434
- }
435
- })
436
- })
437
-
438
- if (client.destroyed) {
439
- util.destroy(socket.on('error', noop), new ClientDestroyedError())
440
- return
441
- }
442
-
443
- assert(socket)
444
-
445
- try {
446
- client[kHTTPContext] = socket.alpnProtocol === 'h2'
447
- ? await connectH2(client, socket)
448
- : await connectH1(client, socket)
449
- } catch (err) {
450
- socket.destroy().on('error', noop)
451
- throw err
452
- }
453
-
454
- client[kConnecting] = false
455
-
456
- socket[kCounter] = 0
457
- socket[kMaxRequests] = client[kMaxRequests]
458
- socket[kClient] = client
459
- socket[kError] = null
460
-
461
- if (channels.connected.hasSubscribers) {
462
- channels.connected.publish({
463
- connectParams: {
464
- host,
465
- hostname,
466
- protocol,
467
- port,
468
- version: client[kHTTPContext]?.version,
469
- servername: client[kServerName],
470
- localAddress: client[kLocalAddress]
471
- },
472
- connector: client[kConnector],
473
- socket
474
- })
475
- }
476
- client.emit('connect', client[kUrl], [client])
477
- } catch (err) {
478
- if (client.destroyed) {
479
- return
480
- }
481
-
482
- client[kConnecting] = false
483
-
484
- if (channels.connectError.hasSubscribers) {
485
- channels.connectError.publish({
486
- connectParams: {
487
- host,
488
- hostname,
489
- protocol,
490
- port,
491
- version: client[kHTTPContext]?.version,
492
- servername: client[kServerName],
493
- localAddress: client[kLocalAddress]
494
- },
495
- connector: client[kConnector],
496
- error: err
497
- })
498
- }
499
-
500
- if (err.code === 'ERR_TLS_CERT_ALTNAME_INVALID') {
501
- assert(client[kRunning] === 0)
502
- while (client[kPending] > 0 && client[kQueue][client[kPendingIdx]].servername === client[kServerName]) {
503
- const request = client[kQueue][client[kPendingIdx]++]
504
- util.errorRequest(client, request, err)
505
- }
506
- } else {
507
- onError(client, err)
508
- }
509
-
510
- client.emit('connectionError', client[kUrl], [client], err)
511
- }
512
-
513
- client[kResume]()
514
- }
515
-
516
- function emitDrain (client) {
517
- client[kNeedDrain] = 0
518
- client.emit('drain', client[kUrl], [client])
519
- }
520
-
521
- function resume (client, sync) {
522
- if (client[kResuming] === 2) {
523
- return
524
- }
525
-
526
- client[kResuming] = 2
527
-
528
- _resume(client, sync)
529
- client[kResuming] = 0
530
-
531
- if (client[kRunningIdx] > 256) {
532
- client[kQueue].splice(0, client[kRunningIdx])
533
- client[kPendingIdx] -= client[kRunningIdx]
534
- client[kRunningIdx] = 0
535
- }
536
- }
537
-
538
- function _resume (client, sync) {
539
- while (true) {
540
- if (client.destroyed) {
541
- assert(client[kPending] === 0)
542
- return
543
- }
544
-
545
- if (client[kClosedResolve] && !client[kSize]) {
546
- client[kClosedResolve]()
547
- client[kClosedResolve] = null
548
- return
549
- }
550
-
551
- if (client[kHTTPContext]) {
552
- client[kHTTPContext].resume()
553
- }
554
-
555
- if (client[kBusy]) {
556
- client[kNeedDrain] = 2
557
- } else if (client[kNeedDrain] === 2) {
558
- if (sync) {
559
- client[kNeedDrain] = 1
560
- queueMicrotask(() => emitDrain(client))
561
- } else {
562
- emitDrain(client)
563
- }
564
- continue
565
- }
566
-
567
- if (client[kPending] === 0) {
568
- return
569
- }
570
-
571
- if (client[kRunning] >= (getPipelining(client) || 1)) {
572
- return
573
- }
574
-
575
- const request = client[kQueue][client[kPendingIdx]]
576
-
577
- if (client[kUrl].protocol === 'https:' && client[kServerName] !== request.servername) {
578
- if (client[kRunning] > 0) {
579
- return
580
- }
581
-
582
- client[kServerName] = request.servername
583
- client[kHTTPContext]?.destroy(new InformationalError('servername changed'), () => {
584
- client[kHTTPContext] = null
585
- resume(client)
586
- })
587
- }
588
-
589
- if (client[kConnecting]) {
590
- return
591
- }
592
-
593
- if (!client[kHTTPContext]) {
594
- connect(client)
595
- return
596
- }
597
-
598
- if (client[kHTTPContext].destroyed) {
599
- return
600
- }
601
-
602
- if (client[kHTTPContext].busy(request)) {
603
- return
604
- }
605
-
606
- if (!request.aborted && client[kHTTPContext].write(request)) {
607
- client[kPendingIdx]++
608
- } else {
609
- client[kQueue].splice(client[kPendingIdx], 1)
610
- }
611
- }
612
- }
613
-
614
- module.exports = Client