deepv-code 1.0.182
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/LICENSE +202 -0
- package/README.md +3 -0
- package/bundle/assets/help/README.md +113 -0
- package/bundle/assets/help/cli-help-knowledge.md +1382 -0
- package/bundle/assets/sounds/README.md +74 -0
- package/bundle/assets/sounds/confirmation-required.wav +0 -0
- package/bundle/assets/sounds/response-complete.wav +0 -0
- package/bundle/assets/sounds/selection-made.wav +0 -0
- package/bundle/dvcode.js +4442 -0
- package/bundle/fix-binary-permissions.js +215 -0
- package/bundle/login/templates/authSelectPage.html +870 -0
- package/bundle/login/templates/deepv.ico +0 -0
- package/bundle/login/templates/feishu.ico +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/darwin-arm64-rg +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/darwin-x64-rg +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/linux-arm-rg +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/linux-arm64-rg +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/linux-x64-rg +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/rg.exe +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/win32-arm64-rg.exe +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/win32-ia32-rg.exe +0 -0
- package/bundle/node_modules/@vscode/ripgrep/bin/win32-x64-rg.exe +0 -0
- package/bundle/node_modules/@vscode/ripgrep/lib/download.js +357 -0
- package/bundle/node_modules/@vscode/ripgrep/lib/index.d.ts +1 -0
- package/bundle/node_modules/@vscode/ripgrep/lib/index.js +42 -0
- package/bundle/node_modules/@vscode/ripgrep/lib/postinstall.js +121 -0
- package/bundle/node_modules/@vscode/ripgrep/package.json +24 -0
- package/bundle/node_modules/undici/LICENSE +21 -0
- package/bundle/node_modules/undici/README.md +472 -0
- package/bundle/node_modules/undici/docs/docs/api/Agent.md +83 -0
- package/bundle/node_modules/undici/docs/docs/api/BalancedPool.md +99 -0
- package/bundle/node_modules/undici/docs/docs/api/CacheStorage.md +30 -0
- package/bundle/node_modules/undici/docs/docs/api/CacheStore.md +151 -0
- package/bundle/node_modules/undici/docs/docs/api/Client.md +281 -0
- package/bundle/node_modules/undici/docs/docs/api/ClientStats.md +27 -0
- package/bundle/node_modules/undici/docs/docs/api/Connector.md +115 -0
- package/bundle/node_modules/undici/docs/docs/api/ContentType.md +57 -0
- package/bundle/node_modules/undici/docs/docs/api/Cookies.md +101 -0
- package/bundle/node_modules/undici/docs/docs/api/Debug.md +62 -0
- package/bundle/node_modules/undici/docs/docs/api/DiagnosticsChannel.md +204 -0
- package/bundle/node_modules/undici/docs/docs/api/Dispatcher.md +1200 -0
- package/bundle/node_modules/undici/docs/docs/api/EnvHttpProxyAgent.md +159 -0
- package/bundle/node_modules/undici/docs/docs/api/Errors.md +49 -0
- package/bundle/node_modules/undici/docs/docs/api/EventSource.md +45 -0
- package/bundle/node_modules/undici/docs/docs/api/Fetch.md +52 -0
- package/bundle/node_modules/undici/docs/docs/api/H2CClient.md +262 -0
- package/bundle/node_modules/undici/docs/docs/api/MockAgent.md +603 -0
- package/bundle/node_modules/undici/docs/docs/api/MockCallHistory.md +197 -0
- package/bundle/node_modules/undici/docs/docs/api/MockCallHistoryLog.md +43 -0
- package/bundle/node_modules/undici/docs/docs/api/MockClient.md +77 -0
- package/bundle/node_modules/undici/docs/docs/api/MockErrors.md +12 -0
- package/bundle/node_modules/undici/docs/docs/api/MockPool.md +548 -0
- package/bundle/node_modules/undici/docs/docs/api/Pool.md +84 -0
- package/bundle/node_modules/undici/docs/docs/api/PoolStats.md +35 -0
- package/bundle/node_modules/undici/docs/docs/api/ProxyAgent.md +227 -0
- package/bundle/node_modules/undici/docs/docs/api/RedirectHandler.md +96 -0
- package/bundle/node_modules/undici/docs/docs/api/RetryAgent.md +45 -0
- package/bundle/node_modules/undici/docs/docs/api/RetryHandler.md +117 -0
- package/bundle/node_modules/undici/docs/docs/api/Util.md +25 -0
- package/bundle/node_modules/undici/docs/docs/api/WebSocket.md +85 -0
- package/bundle/node_modules/undici/docs/docs/api/api-lifecycle.md +91 -0
- package/bundle/node_modules/undici/docs/docs/best-practices/client-certificate.md +64 -0
- package/bundle/node_modules/undici/docs/docs/best-practices/mocking-request.md +190 -0
- package/bundle/node_modules/undici/docs/docs/best-practices/proxy.md +127 -0
- package/bundle/node_modules/undici/docs/docs/best-practices/writing-tests.md +20 -0
- package/bundle/node_modules/undici/index-fetch.js +35 -0
- package/bundle/node_modules/undici/index.d.ts +3 -0
- package/bundle/node_modules/undici/index.js +183 -0
- package/bundle/node_modules/undici/lib/api/abort-signal.js +59 -0
- package/bundle/node_modules/undici/lib/api/api-connect.js +110 -0
- package/bundle/node_modules/undici/lib/api/api-pipeline.js +252 -0
- package/bundle/node_modules/undici/lib/api/api-request.js +199 -0
- package/bundle/node_modules/undici/lib/api/api-stream.js +209 -0
- package/bundle/node_modules/undici/lib/api/api-upgrade.js +110 -0
- package/bundle/node_modules/undici/lib/api/index.js +7 -0
- package/bundle/node_modules/undici/lib/api/readable.js +558 -0
- package/bundle/node_modules/undici/lib/api/util.js +95 -0
- package/bundle/node_modules/undici/lib/cache/memory-cache-store.js +234 -0
- package/bundle/node_modules/undici/lib/cache/sqlite-cache-store.js +461 -0
- package/bundle/node_modules/undici/lib/core/connect.js +164 -0
- package/bundle/node_modules/undici/lib/core/constants.js +143 -0
- package/bundle/node_modules/undici/lib/core/diagnostics.js +196 -0
- package/bundle/node_modules/undici/lib/core/errors.js +244 -0
- package/bundle/node_modules/undici/lib/core/request.js +397 -0
- package/bundle/node_modules/undici/lib/core/symbols.js +68 -0
- package/bundle/node_modules/undici/lib/core/tree.js +160 -0
- package/bundle/node_modules/undici/lib/core/util.js +988 -0
- package/bundle/node_modules/undici/lib/dispatcher/agent.js +135 -0
- package/bundle/node_modules/undici/lib/dispatcher/balanced-pool.js +206 -0
- package/bundle/node_modules/undici/lib/dispatcher/client-h1.js +1615 -0
- package/bundle/node_modules/undici/lib/dispatcher/client-h2.js +798 -0
- package/bundle/node_modules/undici/lib/dispatcher/client.js +614 -0
- package/bundle/node_modules/undici/lib/dispatcher/dispatcher-base.js +161 -0
- package/bundle/node_modules/undici/lib/dispatcher/dispatcher.js +48 -0
- package/bundle/node_modules/undici/lib/dispatcher/env-http-proxy-agent.js +151 -0
- package/bundle/node_modules/undici/lib/dispatcher/fixed-queue.js +159 -0
- package/bundle/node_modules/undici/lib/dispatcher/h2c-client.js +122 -0
- package/bundle/node_modules/undici/lib/dispatcher/pool-base.js +191 -0
- package/bundle/node_modules/undici/lib/dispatcher/pool.js +118 -0
- package/bundle/node_modules/undici/lib/dispatcher/proxy-agent.js +275 -0
- package/bundle/node_modules/undici/lib/dispatcher/retry-agent.js +35 -0
- package/bundle/node_modules/undici/lib/global.js +32 -0
- package/bundle/node_modules/undici/lib/handler/cache-handler.js +448 -0
- package/bundle/node_modules/undici/lib/handler/cache-revalidation-handler.js +124 -0
- package/bundle/node_modules/undici/lib/handler/decorator-handler.js +67 -0
- package/bundle/node_modules/undici/lib/handler/redirect-handler.js +227 -0
- package/bundle/node_modules/undici/lib/handler/retry-handler.js +342 -0
- package/bundle/node_modules/undici/lib/handler/unwrap-handler.js +96 -0
- package/bundle/node_modules/undici/lib/handler/wrap-handler.js +95 -0
- package/bundle/node_modules/undici/lib/interceptor/cache.js +372 -0
- package/bundle/node_modules/undici/lib/interceptor/dns.js +432 -0
- package/bundle/node_modules/undici/lib/interceptor/dump.js +111 -0
- package/bundle/node_modules/undici/lib/interceptor/redirect.js +21 -0
- package/bundle/node_modules/undici/lib/interceptor/response-error.js +95 -0
- package/bundle/node_modules/undici/lib/interceptor/retry.js +19 -0
- package/bundle/node_modules/undici/lib/llhttp/.gitkeep +0 -0
- package/bundle/node_modules/undici/lib/llhttp/constants.d.ts +97 -0
- package/bundle/node_modules/undici/lib/llhttp/constants.js +498 -0
- package/bundle/node_modules/undici/lib/llhttp/constants.js.map +1 -0
- package/bundle/node_modules/undici/lib/llhttp/llhttp-wasm.js +15 -0
- package/bundle/node_modules/undici/lib/llhttp/llhttp_simd-wasm.js +15 -0
- package/bundle/node_modules/undici/lib/llhttp/utils.d.ts +2 -0
- package/bundle/node_modules/undici/lib/llhttp/utils.js +15 -0
- package/bundle/node_modules/undici/lib/llhttp/utils.js.map +1 -0
- package/bundle/node_modules/undici/lib/mock/mock-agent.js +224 -0
- package/bundle/node_modules/undici/lib/mock/mock-call-history.js +248 -0
- package/bundle/node_modules/undici/lib/mock/mock-client.js +64 -0
- package/bundle/node_modules/undici/lib/mock/mock-errors.js +19 -0
- package/bundle/node_modules/undici/lib/mock/mock-interceptor.js +209 -0
- package/bundle/node_modules/undici/lib/mock/mock-pool.js +64 -0
- package/bundle/node_modules/undici/lib/mock/mock-symbols.js +31 -0
- package/bundle/node_modules/undici/lib/mock/mock-utils.js +433 -0
- package/bundle/node_modules/undici/lib/mock/pending-interceptors-formatter.js +43 -0
- package/bundle/node_modules/undici/lib/util/cache.js +368 -0
- package/bundle/node_modules/undici/lib/util/date.js +259 -0
- package/bundle/node_modules/undici/lib/util/stats.js +32 -0
- package/bundle/node_modules/undici/lib/util/timers.js +423 -0
- package/bundle/node_modules/undici/lib/web/cache/cache.js +862 -0
- package/bundle/node_modules/undici/lib/web/cache/cachestorage.js +152 -0
- package/bundle/node_modules/undici/lib/web/cache/util.js +45 -0
- package/bundle/node_modules/undici/lib/web/cookies/constants.js +12 -0
- package/bundle/node_modules/undici/lib/web/cookies/index.js +199 -0
- package/bundle/node_modules/undici/lib/web/cookies/parse.js +322 -0
- package/bundle/node_modules/undici/lib/web/cookies/util.js +282 -0
- package/bundle/node_modules/undici/lib/web/eventsource/eventsource-stream.js +399 -0
- package/bundle/node_modules/undici/lib/web/eventsource/eventsource.js +484 -0
- package/bundle/node_modules/undici/lib/web/eventsource/util.js +37 -0
- package/bundle/node_modules/undici/lib/web/fetch/LICENSE +21 -0
- package/bundle/node_modules/undici/lib/web/fetch/body.js +532 -0
- package/bundle/node_modules/undici/lib/web/fetch/constants.js +131 -0
- package/bundle/node_modules/undici/lib/web/fetch/data-url.js +744 -0
- package/bundle/node_modules/undici/lib/web/fetch/dispatcher-weakref.js +46 -0
- package/bundle/node_modules/undici/lib/web/fetch/formdata-parser.js +501 -0
- package/bundle/node_modules/undici/lib/web/fetch/formdata.js +263 -0
- package/bundle/node_modules/undici/lib/web/fetch/global.js +40 -0
- package/bundle/node_modules/undici/lib/web/fetch/headers.js +719 -0
- package/bundle/node_modules/undici/lib/web/fetch/index.js +2258 -0
- package/bundle/node_modules/undici/lib/web/fetch/request.js +1099 -0
- package/bundle/node_modules/undici/lib/web/fetch/response.js +636 -0
- package/bundle/node_modules/undici/lib/web/fetch/util.js +1782 -0
- package/bundle/node_modules/undici/lib/web/fetch/webidl.js +740 -0
- package/bundle/node_modules/undici/lib/web/websocket/connection.js +325 -0
- package/bundle/node_modules/undici/lib/web/websocket/constants.js +126 -0
- package/bundle/node_modules/undici/lib/web/websocket/events.js +331 -0
- package/bundle/node_modules/undici/lib/web/websocket/frame.js +138 -0
- package/bundle/node_modules/undici/lib/web/websocket/permessage-deflate.js +70 -0
- package/bundle/node_modules/undici/lib/web/websocket/receiver.js +454 -0
- package/bundle/node_modules/undici/lib/web/websocket/sender.js +109 -0
- package/bundle/node_modules/undici/lib/web/websocket/stream/websocketerror.js +83 -0
- package/bundle/node_modules/undici/lib/web/websocket/stream/websocketstream.js +485 -0
- package/bundle/node_modules/undici/lib/web/websocket/util.js +338 -0
- package/bundle/node_modules/undici/lib/web/websocket/websocket.js +686 -0
- package/bundle/node_modules/undici/package.json +149 -0
- package/bundle/node_modules/undici/scripts/strip-comments.js +10 -0
- package/bundle/node_modules/undici/types/README.md +6 -0
- package/bundle/node_modules/undici/types/agent.d.ts +35 -0
- package/bundle/node_modules/undici/types/api.d.ts +43 -0
- package/bundle/node_modules/undici/types/balanced-pool.d.ts +29 -0
- package/bundle/node_modules/undici/types/cache-interceptor.d.ts +172 -0
- package/bundle/node_modules/undici/types/cache.d.ts +36 -0
- package/bundle/node_modules/undici/types/client-stats.d.ts +15 -0
- package/bundle/node_modules/undici/types/client.d.ts +110 -0
- package/bundle/node_modules/undici/types/connector.d.ts +34 -0
- package/bundle/node_modules/undici/types/content-type.d.ts +21 -0
- package/bundle/node_modules/undici/types/cookies.d.ts +30 -0
- package/bundle/node_modules/undici/types/diagnostics-channel.d.ts +66 -0
- package/bundle/node_modules/undici/types/dispatcher.d.ts +281 -0
- package/bundle/node_modules/undici/types/env-http-proxy-agent.d.ts +21 -0
- package/bundle/node_modules/undici/types/errors.d.ts +171 -0
- package/bundle/node_modules/undici/types/eventsource.d.ts +61 -0
- package/bundle/node_modules/undici/types/fetch.d.ts +210 -0
- package/bundle/node_modules/undici/types/formdata.d.ts +108 -0
- package/bundle/node_modules/undici/types/global-dispatcher.d.ts +9 -0
- package/bundle/node_modules/undici/types/global-origin.d.ts +7 -0
- package/bundle/node_modules/undici/types/h2c-client.d.ts +75 -0
- package/bundle/node_modules/undici/types/handlers.d.ts +15 -0
- package/bundle/node_modules/undici/types/header.d.ts +160 -0
- package/bundle/node_modules/undici/types/index.d.ts +75 -0
- package/bundle/node_modules/undici/types/interceptors.d.ts +34 -0
- package/bundle/node_modules/undici/types/mock-agent.d.ts +68 -0
- package/bundle/node_modules/undici/types/mock-call-history.d.ts +111 -0
- package/bundle/node_modules/undici/types/mock-client.d.ts +25 -0
- package/bundle/node_modules/undici/types/mock-errors.d.ts +12 -0
- package/bundle/node_modules/undici/types/mock-interceptor.d.ts +93 -0
- package/bundle/node_modules/undici/types/mock-pool.d.ts +25 -0
- package/bundle/node_modules/undici/types/patch.d.ts +29 -0
- package/bundle/node_modules/undici/types/pool-stats.d.ts +19 -0
- package/bundle/node_modules/undici/types/pool.d.ts +41 -0
- package/bundle/node_modules/undici/types/proxy-agent.d.ts +29 -0
- package/bundle/node_modules/undici/types/readable.d.ts +68 -0
- package/bundle/node_modules/undici/types/retry-agent.d.ts +8 -0
- package/bundle/node_modules/undici/types/retry-handler.d.ts +116 -0
- package/bundle/node_modules/undici/types/util.d.ts +18 -0
- package/bundle/node_modules/undici/types/utility.d.ts +7 -0
- package/bundle/node_modules/undici/types/webidl.d.ts +266 -0
- package/bundle/node_modules/undici/types/websocket.d.ts +184 -0
- package/bundle/sandbox-macos-permissive-closed.sb +26 -0
- package/bundle/sandbox-macos-permissive-open.sb +19 -0
- package/bundle/sandbox-macos-permissive-proxied.sb +31 -0
- package/bundle/sandbox-macos-restrictive-closed.sb +87 -0
- package/bundle/sandbox-macos-restrictive-open.sb +90 -0
- package/bundle/sandbox-macos-restrictive-proxied.sb +92 -0
- package/package.json +137 -0
|
@@ -0,0 +1,614 @@
|
|
|
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
|