undici 6.21.0 → 7.0.0-alpha.10
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/README.md +27 -46
- package/docs/docs/api/Agent.md +14 -17
- package/docs/docs/api/BalancedPool.md +16 -16
- package/docs/docs/api/CacheStore.md +131 -0
- package/docs/docs/api/Client.md +12 -14
- package/docs/docs/api/Debug.md +1 -1
- package/docs/docs/api/Dispatcher.md +98 -194
- package/docs/docs/api/EnvHttpProxyAgent.md +12 -13
- package/docs/docs/api/MockAgent.md +5 -3
- package/docs/docs/api/MockClient.md +5 -5
- package/docs/docs/api/MockPool.md +4 -3
- package/docs/docs/api/Pool.md +15 -16
- package/docs/docs/api/PoolStats.md +1 -1
- package/docs/docs/api/ProxyAgent.md +3 -3
- package/docs/docs/api/RedirectHandler.md +1 -1
- package/docs/docs/api/RetryAgent.md +1 -1
- package/docs/docs/api/RetryHandler.md +4 -4
- package/docs/docs/api/WebSocket.md +46 -4
- package/docs/docs/api/api-lifecycle.md +11 -11
- package/docs/docs/best-practices/mocking-request.md +2 -2
- package/docs/docs/best-practices/proxy.md +1 -1
- package/index.d.ts +1 -1
- package/index.js +23 -7
- package/lib/api/abort-signal.js +2 -0
- package/lib/api/api-connect.js +3 -1
- package/lib/api/api-pipeline.js +7 -6
- package/lib/api/api-request.js +33 -48
- package/lib/api/api-stream.js +39 -50
- package/lib/api/api-upgrade.js +5 -3
- package/lib/api/readable.js +235 -62
- package/lib/api/util.js +2 -0
- package/lib/cache/memory-cache-store.js +177 -0
- package/lib/cache/sqlite-cache-store.js +446 -0
- package/lib/core/constants.js +35 -10
- package/lib/core/diagnostics.js +122 -128
- package/lib/core/errors.js +6 -6
- package/lib/core/request.js +13 -11
- package/lib/core/symbols.js +2 -1
- package/lib/core/tree.js +9 -1
- package/lib/core/util.js +237 -49
- package/lib/dispatcher/agent.js +3 -17
- package/lib/dispatcher/balanced-pool.js +5 -8
- package/lib/dispatcher/client-h1.js +379 -134
- package/lib/dispatcher/client-h2.js +173 -107
- package/lib/dispatcher/client.js +19 -32
- package/lib/dispatcher/dispatcher-base.js +6 -35
- package/lib/dispatcher/dispatcher.js +7 -24
- package/lib/dispatcher/fixed-queue.js +91 -49
- package/lib/dispatcher/pool-stats.js +2 -0
- package/lib/dispatcher/pool.js +3 -6
- package/lib/dispatcher/proxy-agent.js +3 -6
- package/lib/handler/cache-handler.js +393 -0
- package/lib/handler/cache-revalidation-handler.js +124 -0
- package/lib/handler/decorator-handler.js +27 -0
- package/lib/handler/redirect-handler.js +54 -59
- package/lib/handler/retry-handler.js +77 -109
- package/lib/handler/unwrap-handler.js +96 -0
- package/lib/handler/wrap-handler.js +98 -0
- package/lib/interceptor/cache.js +350 -0
- package/lib/interceptor/dns.js +375 -0
- package/lib/interceptor/dump.js +2 -2
- package/lib/interceptor/redirect.js +11 -14
- package/lib/interceptor/response-error.js +18 -7
- package/lib/llhttp/constants.d.ts +97 -0
- package/lib/llhttp/constants.js +412 -192
- package/lib/llhttp/constants.js.map +1 -0
- package/lib/llhttp/llhttp-wasm.js +11 -1
- package/lib/llhttp/llhttp_simd-wasm.js +11 -1
- package/lib/llhttp/utils.d.ts +2 -0
- package/lib/llhttp/utils.js +9 -9
- package/lib/llhttp/utils.js.map +1 -0
- package/lib/mock/mock-agent.js +5 -8
- package/lib/mock/mock-client.js +9 -4
- package/lib/mock/mock-errors.js +3 -1
- package/lib/mock/mock-interceptor.js +8 -6
- package/lib/mock/mock-pool.js +9 -4
- package/lib/mock/mock-symbols.js +3 -1
- package/lib/mock/mock-utils.js +29 -5
- package/lib/util/cache.js +360 -0
- package/lib/web/cache/cache.js +24 -21
- package/lib/web/cache/cachestorage.js +1 -1
- package/lib/web/cookies/index.js +29 -14
- package/lib/web/cookies/parse.js +8 -3
- package/lib/web/eventsource/eventsource-stream.js +9 -8
- package/lib/web/eventsource/eventsource.js +10 -6
- package/lib/web/fetch/body.js +43 -41
- package/lib/web/fetch/constants.js +12 -5
- package/lib/web/fetch/data-url.js +3 -3
- package/lib/web/fetch/formdata-parser.js +72 -45
- package/lib/web/fetch/formdata.js +65 -54
- package/lib/web/fetch/headers.js +118 -86
- package/lib/web/fetch/index.js +58 -67
- package/lib/web/fetch/request.js +136 -77
- package/lib/web/fetch/response.js +87 -56
- package/lib/web/fetch/util.js +259 -109
- package/lib/web/fetch/webidl.js +113 -68
- package/lib/web/websocket/connection.js +76 -147
- package/lib/web/websocket/constants.js +70 -10
- package/lib/web/websocket/events.js +4 -2
- package/lib/web/websocket/frame.js +45 -3
- package/lib/web/websocket/receiver.js +29 -33
- package/lib/web/websocket/sender.js +18 -13
- package/lib/web/websocket/stream/websocketerror.js +83 -0
- package/lib/web/websocket/stream/websocketstream.js +485 -0
- package/lib/web/websocket/util.js +128 -77
- package/lib/web/websocket/websocket.js +234 -135
- package/package.json +24 -36
- package/scripts/strip-comments.js +3 -1
- package/types/agent.d.ts +7 -7
- package/types/api.d.ts +24 -24
- package/types/balanced-pool.d.ts +11 -11
- package/types/cache-interceptor.d.ts +172 -0
- package/types/client.d.ts +11 -12
- package/types/cookies.d.ts +2 -0
- package/types/diagnostics-channel.d.ts +10 -10
- package/types/dispatcher.d.ts +113 -90
- package/types/env-http-proxy-agent.d.ts +2 -2
- package/types/errors.d.ts +53 -47
- package/types/fetch.d.ts +17 -16
- package/types/formdata.d.ts +7 -7
- package/types/global-dispatcher.d.ts +4 -4
- package/types/global-origin.d.ts +5 -5
- package/types/handlers.d.ts +7 -7
- package/types/header.d.ts +157 -1
- package/types/index.d.ts +44 -46
- package/types/interceptors.d.ts +25 -8
- package/types/mock-agent.d.ts +21 -18
- package/types/mock-client.d.ts +4 -4
- package/types/mock-errors.d.ts +3 -3
- package/types/mock-interceptor.d.ts +19 -19
- package/types/mock-pool.d.ts +4 -4
- package/types/patch.d.ts +0 -4
- package/types/pool-stats.d.ts +8 -8
- package/types/pool.d.ts +12 -12
- package/types/proxy-agent.d.ts +4 -4
- package/types/readable.d.ts +18 -15
- package/types/retry-agent.d.ts +1 -1
- package/types/retry-handler.d.ts +10 -10
- package/types/util.d.ts +3 -3
- package/types/utility.d.ts +7 -0
- package/types/webidl.d.ts +44 -6
- package/types/websocket.d.ts +34 -1
- package/docs/docs/api/DispatchInterceptor.md +0 -60
- package/lib/interceptor/redirect-interceptor.js +0 -21
- package/lib/mock/pluralizer.js +0 -29
- package/lib/web/cache/symbols.js +0 -5
- package/lib/web/fetch/file.js +0 -126
- package/lib/web/fetch/symbols.js +0 -9
- package/lib/web/fileapi/encoding.js +0 -290
- package/lib/web/fileapi/filereader.js +0 -344
- package/lib/web/fileapi/progressevent.js +0 -78
- package/lib/web/fileapi/symbols.js +0 -10
- package/lib/web/fileapi/util.js +0 -391
- package/lib/web/websocket/symbols.js +0 -12
- package/types/file.d.ts +0 -39
- package/types/filereader.d.ts +0 -54
package/lib/core/diagnostics.js
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
|
|
2
3
|
const diagnosticsChannel = require('node:diagnostics_channel')
|
|
3
4
|
const util = require('node:util')
|
|
4
5
|
|
|
5
6
|
const undiciDebugLog = util.debuglog('undici')
|
|
6
7
|
const fetchDebuglog = util.debuglog('fetch')
|
|
7
8
|
const websocketDebuglog = util.debuglog('websocket')
|
|
8
|
-
|
|
9
|
+
|
|
9
10
|
const channels = {
|
|
10
11
|
// Client
|
|
11
12
|
beforeConnect: diagnosticsChannel.channel('undici:client:beforeConnect'),
|
|
@@ -26,102 +27,21 @@ const channels = {
|
|
|
26
27
|
pong: diagnosticsChannel.channel('undici:websocket:pong')
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
|
|
30
|
-
const debuglog = fetchDebuglog.enabled ? fetchDebuglog : undiciDebugLog
|
|
31
|
-
|
|
32
|
-
// Track all Client events
|
|
33
|
-
diagnosticsChannel.channel('undici:client:beforeConnect').subscribe(evt => {
|
|
34
|
-
const {
|
|
35
|
-
connectParams: { version, protocol, port, host }
|
|
36
|
-
} = evt
|
|
37
|
-
debuglog(
|
|
38
|
-
'connecting to %s using %s%s',
|
|
39
|
-
`${host}${port ? `:${port}` : ''}`,
|
|
40
|
-
protocol,
|
|
41
|
-
version
|
|
42
|
-
)
|
|
43
|
-
})
|
|
44
|
-
|
|
45
|
-
diagnosticsChannel.channel('undici:client:connected').subscribe(evt => {
|
|
46
|
-
const {
|
|
47
|
-
connectParams: { version, protocol, port, host }
|
|
48
|
-
} = evt
|
|
49
|
-
debuglog(
|
|
50
|
-
'connected to %s using %s%s',
|
|
51
|
-
`${host}${port ? `:${port}` : ''}`,
|
|
52
|
-
protocol,
|
|
53
|
-
version
|
|
54
|
-
)
|
|
55
|
-
})
|
|
56
|
-
|
|
57
|
-
diagnosticsChannel.channel('undici:client:connectError').subscribe(evt => {
|
|
58
|
-
const {
|
|
59
|
-
connectParams: { version, protocol, port, host },
|
|
60
|
-
error
|
|
61
|
-
} = evt
|
|
62
|
-
debuglog(
|
|
63
|
-
'connection to %s using %s%s errored - %s',
|
|
64
|
-
`${host}${port ? `:${port}` : ''}`,
|
|
65
|
-
protocol,
|
|
66
|
-
version,
|
|
67
|
-
error.message
|
|
68
|
-
)
|
|
69
|
-
})
|
|
70
|
-
|
|
71
|
-
diagnosticsChannel.channel('undici:client:sendHeaders').subscribe(evt => {
|
|
72
|
-
const {
|
|
73
|
-
request: { method, path, origin }
|
|
74
|
-
} = evt
|
|
75
|
-
debuglog('sending request to %s %s/%s', method, origin, path)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
// Track Request events
|
|
79
|
-
diagnosticsChannel.channel('undici:request:headers').subscribe(evt => {
|
|
80
|
-
const {
|
|
81
|
-
request: { method, path, origin },
|
|
82
|
-
response: { statusCode }
|
|
83
|
-
} = evt
|
|
84
|
-
debuglog(
|
|
85
|
-
'received response to %s %s/%s - HTTP %d',
|
|
86
|
-
method,
|
|
87
|
-
origin,
|
|
88
|
-
path,
|
|
89
|
-
statusCode
|
|
90
|
-
)
|
|
91
|
-
})
|
|
92
|
-
|
|
93
|
-
diagnosticsChannel.channel('undici:request:trailers').subscribe(evt => {
|
|
94
|
-
const {
|
|
95
|
-
request: { method, path, origin }
|
|
96
|
-
} = evt
|
|
97
|
-
debuglog('trailers received from %s %s/%s', method, origin, path)
|
|
98
|
-
})
|
|
99
|
-
|
|
100
|
-
diagnosticsChannel.channel('undici:request:error').subscribe(evt => {
|
|
101
|
-
const {
|
|
102
|
-
request: { method, path, origin },
|
|
103
|
-
error
|
|
104
|
-
} = evt
|
|
105
|
-
debuglog(
|
|
106
|
-
'request to %s %s/%s errored - %s',
|
|
107
|
-
method,
|
|
108
|
-
origin,
|
|
109
|
-
path,
|
|
110
|
-
error.message
|
|
111
|
-
)
|
|
112
|
-
})
|
|
113
|
-
|
|
114
|
-
isClientSet = true
|
|
115
|
-
}
|
|
30
|
+
let isTrackingClientEvents = false
|
|
116
31
|
|
|
117
|
-
|
|
118
|
-
if (
|
|
119
|
-
|
|
120
|
-
|
|
32
|
+
function trackClientEvents (debugLog = undiciDebugLog) {
|
|
33
|
+
if (isTrackingClientEvents) {
|
|
34
|
+
return
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
isTrackingClientEvents = true
|
|
38
|
+
|
|
39
|
+
diagnosticsChannel.subscribe('undici:client:beforeConnect',
|
|
40
|
+
evt => {
|
|
121
41
|
const {
|
|
122
42
|
connectParams: { version, protocol, port, host }
|
|
123
43
|
} = evt
|
|
124
|
-
|
|
44
|
+
debugLog(
|
|
125
45
|
'connecting to %s%s using %s%s',
|
|
126
46
|
host,
|
|
127
47
|
port ? `:${port}` : '',
|
|
@@ -130,11 +50,12 @@ if (websocketDebuglog.enabled) {
|
|
|
130
50
|
)
|
|
131
51
|
})
|
|
132
52
|
|
|
133
|
-
|
|
53
|
+
diagnosticsChannel.subscribe('undici:client:connected',
|
|
54
|
+
evt => {
|
|
134
55
|
const {
|
|
135
56
|
connectParams: { version, protocol, port, host }
|
|
136
57
|
} = evt
|
|
137
|
-
|
|
58
|
+
debugLog(
|
|
138
59
|
'connected to %s%s using %s%s',
|
|
139
60
|
host,
|
|
140
61
|
port ? `:${port}` : '',
|
|
@@ -143,12 +64,13 @@ if (websocketDebuglog.enabled) {
|
|
|
143
64
|
)
|
|
144
65
|
})
|
|
145
66
|
|
|
146
|
-
|
|
67
|
+
diagnosticsChannel.subscribe('undici:client:connectError',
|
|
68
|
+
evt => {
|
|
147
69
|
const {
|
|
148
70
|
connectParams: { version, protocol, port, host },
|
|
149
71
|
error
|
|
150
72
|
} = evt
|
|
151
|
-
|
|
73
|
+
debugLog(
|
|
152
74
|
'connection to %s%s using %s%s errored - %s',
|
|
153
75
|
host,
|
|
154
76
|
port ? `:${port}` : '',
|
|
@@ -158,43 +80,115 @@ if (websocketDebuglog.enabled) {
|
|
|
158
80
|
)
|
|
159
81
|
})
|
|
160
82
|
|
|
161
|
-
|
|
83
|
+
diagnosticsChannel.subscribe('undici:client:sendHeaders',
|
|
84
|
+
evt => {
|
|
85
|
+
const {
|
|
86
|
+
request: { method, path, origin }
|
|
87
|
+
} = evt
|
|
88
|
+
debugLog('sending request to %s %s/%s', method, origin, path)
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
let isTrackingRequestEvents = false
|
|
93
|
+
|
|
94
|
+
function trackRequestEvents (debugLog = undiciDebugLog) {
|
|
95
|
+
if (isTrackingRequestEvents) {
|
|
96
|
+
return
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
isTrackingRequestEvents = true
|
|
100
|
+
|
|
101
|
+
diagnosticsChannel.subscribe('undici:request:headers',
|
|
102
|
+
evt => {
|
|
103
|
+
const {
|
|
104
|
+
request: { method, path, origin },
|
|
105
|
+
response: { statusCode }
|
|
106
|
+
} = evt
|
|
107
|
+
debugLog(
|
|
108
|
+
'received response to %s %s/%s - HTTP %d',
|
|
109
|
+
method,
|
|
110
|
+
origin,
|
|
111
|
+
path,
|
|
112
|
+
statusCode
|
|
113
|
+
)
|
|
114
|
+
})
|
|
115
|
+
|
|
116
|
+
diagnosticsChannel.subscribe('undici:request:trailers',
|
|
117
|
+
evt => {
|
|
162
118
|
const {
|
|
163
119
|
request: { method, path, origin }
|
|
164
120
|
} = evt
|
|
165
|
-
|
|
121
|
+
debugLog('trailers received from %s %s/%s', method, origin, path)
|
|
122
|
+
})
|
|
123
|
+
|
|
124
|
+
diagnosticsChannel.subscribe('undici:request:error',
|
|
125
|
+
evt => {
|
|
126
|
+
const {
|
|
127
|
+
request: { method, path, origin },
|
|
128
|
+
error
|
|
129
|
+
} = evt
|
|
130
|
+
debugLog(
|
|
131
|
+
'request to %s %s/%s errored - %s',
|
|
132
|
+
method,
|
|
133
|
+
origin,
|
|
134
|
+
path,
|
|
135
|
+
error.message
|
|
136
|
+
)
|
|
166
137
|
})
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let isTrackingWebSocketEvents = false
|
|
141
|
+
|
|
142
|
+
function trackWebSocketEvents (debugLog = websocketDebuglog) {
|
|
143
|
+
if (isTrackingWebSocketEvents) {
|
|
144
|
+
return
|
|
167
145
|
}
|
|
168
146
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
websocket
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
diagnosticsChannel.
|
|
196
|
-
|
|
197
|
-
|
|
147
|
+
isTrackingWebSocketEvents = true
|
|
148
|
+
|
|
149
|
+
diagnosticsChannel.subscribe('undici:websocket:open',
|
|
150
|
+
evt => {
|
|
151
|
+
const {
|
|
152
|
+
address: { address, port }
|
|
153
|
+
} = evt
|
|
154
|
+
debugLog('connection opened %s%s', address, port ? `:${port}` : '')
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
diagnosticsChannel.subscribe('undici:websocket:close',
|
|
158
|
+
evt => {
|
|
159
|
+
const { websocket, code, reason } = evt
|
|
160
|
+
debugLog(
|
|
161
|
+
'closed connection to %s - %s %s',
|
|
162
|
+
websocket.url,
|
|
163
|
+
code,
|
|
164
|
+
reason
|
|
165
|
+
)
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
diagnosticsChannel.subscribe('undici:websocket:socket_error',
|
|
169
|
+
err => {
|
|
170
|
+
debugLog('connection errored - %s', err.message)
|
|
171
|
+
})
|
|
172
|
+
|
|
173
|
+
diagnosticsChannel.subscribe('undici:websocket:ping',
|
|
174
|
+
evt => {
|
|
175
|
+
debugLog('ping received')
|
|
176
|
+
})
|
|
177
|
+
|
|
178
|
+
diagnosticsChannel.subscribe('undici:websocket:pong',
|
|
179
|
+
evt => {
|
|
180
|
+
debugLog('pong received')
|
|
181
|
+
})
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
if (undiciDebugLog.enabled || fetchDebuglog.enabled) {
|
|
185
|
+
trackClientEvents(fetchDebuglog.enabled ? fetchDebuglog : undiciDebugLog)
|
|
186
|
+
trackRequestEvents(fetchDebuglog.enabled ? fetchDebuglog : undiciDebugLog)
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
if (websocketDebuglog.enabled) {
|
|
190
|
+
trackClientEvents(undiciDebugLog.enabled ? undiciDebugLog : websocketDebuglog)
|
|
191
|
+
trackWebSocketEvents(websocketDebuglog)
|
|
198
192
|
}
|
|
199
193
|
|
|
200
194
|
module.exports = {
|
package/lib/core/errors.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
'use strict'
|
|
2
2
|
|
|
3
3
|
class UndiciError extends Error {
|
|
4
|
-
constructor (message) {
|
|
5
|
-
super(message)
|
|
4
|
+
constructor (message, options) {
|
|
5
|
+
super(message, options)
|
|
6
6
|
this.name = 'UndiciError'
|
|
7
7
|
this.code = 'UND_ERR'
|
|
8
8
|
}
|
|
@@ -196,20 +196,20 @@ class RequestRetryError extends UndiciError {
|
|
|
196
196
|
}
|
|
197
197
|
|
|
198
198
|
class ResponseError extends UndiciError {
|
|
199
|
-
constructor (message, code, { headers,
|
|
199
|
+
constructor (message, code, { headers, body }) {
|
|
200
200
|
super(message)
|
|
201
201
|
this.name = 'ResponseError'
|
|
202
202
|
this.message = message || 'Response error'
|
|
203
203
|
this.code = 'UND_ERR_RESPONSE'
|
|
204
204
|
this.statusCode = code
|
|
205
|
-
this.
|
|
205
|
+
this.body = body
|
|
206
206
|
this.headers = headers
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
|
|
210
210
|
class SecureProxyConnectionError extends UndiciError {
|
|
211
|
-
constructor (cause, message, options) {
|
|
212
|
-
super(message, { cause, ...
|
|
211
|
+
constructor (cause, message, options = {}) {
|
|
212
|
+
super(message, { cause, ...options })
|
|
213
213
|
this.name = 'SecureProxyConnectionError'
|
|
214
214
|
this.message = message || 'Secure Proxy Connection failed'
|
|
215
215
|
this.code = 'UND_ERR_PRX_TLS'
|
package/lib/core/request.js
CHANGED
|
@@ -14,8 +14,8 @@ const {
|
|
|
14
14
|
isFormDataLike,
|
|
15
15
|
isIterable,
|
|
16
16
|
isBlobLike,
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
serializePathWithQuery,
|
|
18
|
+
assertRequestHandler,
|
|
19
19
|
getServerName,
|
|
20
20
|
normalizedMethodRecords
|
|
21
21
|
} = require('./util')
|
|
@@ -40,9 +40,9 @@ class Request {
|
|
|
40
40
|
headersTimeout,
|
|
41
41
|
bodyTimeout,
|
|
42
42
|
reset,
|
|
43
|
-
throwOnError,
|
|
44
43
|
expectContinue,
|
|
45
|
-
servername
|
|
44
|
+
servername,
|
|
45
|
+
throwOnError
|
|
46
46
|
}, handler) {
|
|
47
47
|
if (typeof path !== 'string') {
|
|
48
48
|
throw new InvalidArgumentError('path must be a string')
|
|
@@ -82,12 +82,14 @@ class Request {
|
|
|
82
82
|
throw new InvalidArgumentError('invalid expectContinue')
|
|
83
83
|
}
|
|
84
84
|
|
|
85
|
+
if (throwOnError != null) {
|
|
86
|
+
throw new InvalidArgumentError('invalid throwOnError')
|
|
87
|
+
}
|
|
88
|
+
|
|
85
89
|
this.headersTimeout = headersTimeout
|
|
86
90
|
|
|
87
91
|
this.bodyTimeout = bodyTimeout
|
|
88
92
|
|
|
89
|
-
this.throwOnError = throwOnError === true
|
|
90
|
-
|
|
91
93
|
this.method = method
|
|
92
94
|
|
|
93
95
|
this.abort = null
|
|
@@ -128,12 +130,11 @@ class Request {
|
|
|
128
130
|
}
|
|
129
131
|
|
|
130
132
|
this.completed = false
|
|
131
|
-
|
|
132
133
|
this.aborted = false
|
|
133
134
|
|
|
134
135
|
this.upgrade = upgrade || null
|
|
135
136
|
|
|
136
|
-
this.path = query ?
|
|
137
|
+
this.path = query ? serializePathWithQuery(path, query) : path
|
|
137
138
|
|
|
138
139
|
this.origin = origin
|
|
139
140
|
|
|
@@ -141,7 +142,7 @@ class Request {
|
|
|
141
142
|
? method === 'HEAD' || method === 'GET'
|
|
142
143
|
: idempotent
|
|
143
144
|
|
|
144
|
-
this.blocking = blocking
|
|
145
|
+
this.blocking = blocking ?? this.method !== 'HEAD'
|
|
145
146
|
|
|
146
147
|
this.reset = reset == null ? null : reset
|
|
147
148
|
|
|
@@ -181,9 +182,9 @@ class Request {
|
|
|
181
182
|
throw new InvalidArgumentError('headers must be an object or an array')
|
|
182
183
|
}
|
|
183
184
|
|
|
184
|
-
|
|
185
|
+
assertRequestHandler(handler, method, upgrade)
|
|
185
186
|
|
|
186
|
-
this.servername = servername || getServerName(this.host)
|
|
187
|
+
this.servername = servername || getServerName(this.host) || null
|
|
187
188
|
|
|
188
189
|
this[kHandler] = handler
|
|
189
190
|
|
|
@@ -270,6 +271,7 @@ class Request {
|
|
|
270
271
|
this.onFinally()
|
|
271
272
|
|
|
272
273
|
assert(!this.aborted)
|
|
274
|
+
assert(!this.completed)
|
|
273
275
|
|
|
274
276
|
this.completed = true
|
|
275
277
|
if (channels.trailers.hasSubscribers) {
|
package/lib/core/symbols.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
1
3
|
module.exports = {
|
|
2
4
|
kClose: Symbol('close'),
|
|
3
5
|
kDestroy: Symbol('destroy'),
|
|
@@ -52,7 +54,6 @@ module.exports = {
|
|
|
52
54
|
kMaxRequests: Symbol('maxRequestsPerClient'),
|
|
53
55
|
kProxy: Symbol('proxy agent options'),
|
|
54
56
|
kCounter: Symbol('socket request counter'),
|
|
55
|
-
kInterceptors: Symbol('dispatch interceptors'),
|
|
56
57
|
kMaxResponseSize: Symbol('max response size'),
|
|
57
58
|
kHTTP2Session: Symbol('http2Session'),
|
|
58
59
|
kHTTP2SessionState: Symbol('http2Session state'),
|
package/lib/core/tree.js
CHANGED
|
@@ -40,6 +40,7 @@ class TstNode {
|
|
|
40
40
|
/**
|
|
41
41
|
* @param {string} key
|
|
42
42
|
* @param {any} value
|
|
43
|
+
* @returns {void}
|
|
43
44
|
*/
|
|
44
45
|
add (key, value) {
|
|
45
46
|
const length = key.length
|
|
@@ -47,6 +48,9 @@ class TstNode {
|
|
|
47
48
|
throw new TypeError('Unreachable')
|
|
48
49
|
}
|
|
49
50
|
let index = 0
|
|
51
|
+
/**
|
|
52
|
+
* @type {TstNode}
|
|
53
|
+
*/
|
|
50
54
|
let node = this
|
|
51
55
|
while (true) {
|
|
52
56
|
const code = key.charCodeAt(index)
|
|
@@ -87,6 +91,9 @@ class TstNode {
|
|
|
87
91
|
search (key) {
|
|
88
92
|
const keylength = key.length
|
|
89
93
|
let index = 0
|
|
94
|
+
/**
|
|
95
|
+
* @type {TstNode|null}
|
|
96
|
+
*/
|
|
90
97
|
let node = this
|
|
91
98
|
while (node !== null && index < keylength) {
|
|
92
99
|
let code = key[index]
|
|
@@ -121,6 +128,7 @@ class TernarySearchTree {
|
|
|
121
128
|
/**
|
|
122
129
|
* @param {string} key
|
|
123
130
|
* @param {any} value
|
|
131
|
+
* @returns {void}
|
|
124
132
|
* */
|
|
125
133
|
insert (key, value) {
|
|
126
134
|
if (this.node === null) {
|
|
@@ -132,7 +140,7 @@ class TernarySearchTree {
|
|
|
132
140
|
|
|
133
141
|
/**
|
|
134
142
|
* @param {Uint8Array} key
|
|
135
|
-
* @
|
|
143
|
+
* @returns {any}
|
|
136
144
|
*/
|
|
137
145
|
lookup (key) {
|
|
138
146
|
return this.node?.search(key)?.value ?? null
|