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