undici 6.19.7 → 7.0.0-alpha.1
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 +5 -9
- package/docs/docs/api/Agent.md +0 -3
- package/docs/docs/api/Client.md +0 -2
- package/docs/docs/api/Dispatcher.md +204 -6
- package/docs/docs/api/EnvHttpProxyAgent.md +0 -1
- package/docs/docs/api/Fetch.md +1 -0
- package/docs/docs/api/Pool.md +0 -1
- package/docs/docs/api/RetryHandler.md +1 -1
- package/index.js +0 -4
- package/lib/api/api-connect.js +3 -1
- package/lib/api/api-pipeline.js +3 -4
- package/lib/api/api-request.js +29 -46
- package/lib/api/api-stream.js +36 -49
- package/lib/api/api-upgrade.js +5 -3
- package/lib/api/readable.js +71 -27
- package/lib/core/connect.js +39 -24
- package/lib/core/errors.js +17 -4
- package/lib/core/request.js +7 -5
- package/lib/core/symbols.js +0 -1
- package/lib/core/tree.js +6 -0
- package/lib/core/util.js +1 -11
- package/lib/dispatcher/agent.js +3 -17
- package/lib/dispatcher/balanced-pool.js +27 -11
- package/lib/dispatcher/client-h1.js +44 -39
- package/lib/dispatcher/client.js +3 -27
- package/lib/dispatcher/dispatcher-base.js +2 -34
- package/lib/dispatcher/dispatcher.js +3 -24
- package/lib/dispatcher/pool.js +3 -6
- package/lib/dispatcher/proxy-agent.js +3 -6
- package/lib/handler/decorator-handler.js +24 -0
- package/lib/handler/redirect-handler.js +9 -0
- package/lib/handler/retry-handler.js +22 -3
- package/lib/interceptor/dump.js +2 -2
- package/lib/interceptor/redirect.js +11 -14
- package/lib/interceptor/response-error.js +89 -0
- 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-client.js +2 -2
- package/lib/mock/mock-pool.js +2 -2
- package/lib/mock/mock-symbols.js +1 -0
- package/lib/util/timers.js +324 -44
- package/lib/web/cookies/index.js +15 -13
- package/lib/web/cookies/parse.js +2 -2
- package/lib/web/eventsource/eventsource-stream.js +9 -8
- package/lib/web/eventsource/eventsource.js +10 -6
- package/lib/web/fetch/body.js +31 -11
- package/lib/web/fetch/data-url.js +1 -1
- package/lib/web/fetch/formdata-parser.js +1 -2
- package/lib/web/fetch/formdata.js +28 -37
- package/lib/web/fetch/headers.js +1 -1
- package/lib/web/fetch/index.js +7 -8
- package/lib/web/fetch/request.js +11 -28
- package/lib/web/fetch/response.js +13 -41
- package/lib/web/fetch/symbols.js +0 -1
- package/lib/web/fetch/util.js +3 -12
- package/lib/web/fetch/webidl.js +73 -62
- package/lib/web/websocket/connection.js +26 -174
- package/lib/web/websocket/constants.js +1 -1
- package/lib/web/websocket/frame.js +45 -3
- package/lib/web/websocket/receiver.js +28 -26
- package/lib/web/websocket/sender.js +18 -13
- package/lib/web/websocket/util.js +20 -74
- package/lib/web/websocket/websocket.js +294 -70
- package/package.json +16 -29
- 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/client.d.ts +11 -12
- package/types/diagnostics-channel.d.ts +10 -10
- package/types/dispatcher.d.ts +96 -97
- package/types/env-http-proxy-agent.d.ts +2 -2
- package/types/errors.d.ts +53 -47
- package/types/eventsource.d.ts +0 -2
- package/types/fetch.d.ts +8 -8
- 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 +4 -4
- package/types/header.d.ts +157 -1
- package/types/index.d.ts +42 -46
- package/types/interceptors.d.ts +10 -8
- package/types/mock-agent.d.ts +18 -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 -42
- 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 +14 -9
- package/types/retry-agent.d.ts +1 -1
- package/types/retry-handler.d.ts +8 -8
- package/types/util.d.ts +3 -3
- package/types/utility.d.ts +7 -0
- package/types/webidl.d.ts +22 -4
- package/types/websocket.d.ts +1 -3
- package/docs/docs/api/DispatchInterceptor.md +0 -60
- package/lib/interceptor/redirect-interceptor.js +0 -21
- package/lib/web/fetch/file.js +0 -126
- 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
|
@@ -1,24 +1,21 @@
|
|
|
1
1
|
'use strict'
|
|
2
|
+
|
|
2
3
|
const RedirectHandler = require('../handler/redirect-handler')
|
|
3
4
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const { maxRedirections = globalMaxRedirections, ...baseOpts } = opts
|
|
5
|
+
function createRedirectInterceptor ({ maxRedirections: defaultMaxRedirections } = {}) {
|
|
6
|
+
return (dispatch) => {
|
|
7
|
+
return function Intercept (opts, handler) {
|
|
8
|
+
const { maxRedirections = defaultMaxRedirections, ...rest } = opts
|
|
9
9
|
|
|
10
|
-
if (
|
|
10
|
+
if (maxRedirections == null || maxRedirections === 0) {
|
|
11
11
|
return dispatch(opts, handler)
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
-
const
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
opts,
|
|
18
|
-
handler
|
|
19
|
-
)
|
|
20
|
-
|
|
21
|
-
return dispatch(baseOpts, redirectHandler)
|
|
14
|
+
const dispatchOpts = { ...rest, maxRedirections: 0 } // Stop sub dispatcher from also redirecting.
|
|
15
|
+
const redirectHandler = new RedirectHandler(dispatch, maxRedirections, dispatchOpts, handler)
|
|
16
|
+
return dispatch(dispatchOpts, redirectHandler)
|
|
22
17
|
}
|
|
23
18
|
}
|
|
24
19
|
}
|
|
20
|
+
|
|
21
|
+
module.exports = createRedirectInterceptor
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
const { parseHeaders } = require('../core/util')
|
|
4
|
+
const DecoratorHandler = require('../handler/decorator-handler')
|
|
5
|
+
const { ResponseError } = require('../core/errors')
|
|
6
|
+
|
|
7
|
+
class Handler extends DecoratorHandler {
|
|
8
|
+
#handler
|
|
9
|
+
#statusCode
|
|
10
|
+
#contentType
|
|
11
|
+
#decoder
|
|
12
|
+
#headers
|
|
13
|
+
#body
|
|
14
|
+
|
|
15
|
+
constructor (opts, { handler }) {
|
|
16
|
+
super(handler)
|
|
17
|
+
this.#handler = handler
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
onConnect (abort) {
|
|
21
|
+
this.#statusCode = 0
|
|
22
|
+
this.#contentType = null
|
|
23
|
+
this.#decoder = null
|
|
24
|
+
this.#headers = null
|
|
25
|
+
this.#body = ''
|
|
26
|
+
|
|
27
|
+
return this.#handler.onConnect(abort)
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
onHeaders (statusCode, rawHeaders, resume, statusMessage, headers = parseHeaders(rawHeaders)) {
|
|
31
|
+
this.#statusCode = statusCode
|
|
32
|
+
this.#headers = headers
|
|
33
|
+
this.#contentType = headers['content-type']
|
|
34
|
+
|
|
35
|
+
if (this.#statusCode < 400) {
|
|
36
|
+
return this.#handler.onHeaders(statusCode, rawHeaders, resume, statusMessage, headers)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (this.#contentType === 'application/json' || this.#contentType === 'text/plain') {
|
|
40
|
+
this.#decoder = new TextDecoder('utf-8')
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
onData (chunk) {
|
|
45
|
+
if (this.#statusCode < 400) {
|
|
46
|
+
return this.#handler.onData(chunk)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
this.#body += this.#decoder?.decode(chunk, { stream: true }) ?? ''
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
onComplete (rawTrailers) {
|
|
53
|
+
if (this.#statusCode >= 400) {
|
|
54
|
+
this.#body += this.#decoder?.decode(undefined, { stream: false }) ?? ''
|
|
55
|
+
|
|
56
|
+
if (this.#contentType === 'application/json') {
|
|
57
|
+
try {
|
|
58
|
+
this.#body = JSON.parse(this.#body)
|
|
59
|
+
} catch {
|
|
60
|
+
// Do nothing...
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
let err
|
|
65
|
+
const stackTraceLimit = Error.stackTraceLimit
|
|
66
|
+
Error.stackTraceLimit = 0
|
|
67
|
+
try {
|
|
68
|
+
err = new ResponseError('Response Error', this.#statusCode, {
|
|
69
|
+
data: this.#body,
|
|
70
|
+
headers: this.#headers
|
|
71
|
+
})
|
|
72
|
+
} finally {
|
|
73
|
+
Error.stackTraceLimit = stackTraceLimit
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
this.#handler.onError(err)
|
|
77
|
+
} else {
|
|
78
|
+
this.#handler.onComplete(rawTrailers)
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
onError (err) {
|
|
83
|
+
this.#handler.onError(err)
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
module.exports = (dispatch) => (opts, handler) => opts.throwOnError
|
|
88
|
+
? dispatch(opts, new Handler(opts, { handler }))
|
|
89
|
+
: dispatch(opts, handler)
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
export type IntDict = Record<string, number>;
|
|
2
|
+
export declare const ERROR: IntDict;
|
|
3
|
+
export declare const TYPE: IntDict;
|
|
4
|
+
export declare const FLAGS: IntDict;
|
|
5
|
+
export declare const LENIENT_FLAGS: IntDict;
|
|
6
|
+
export declare const METHODS: IntDict;
|
|
7
|
+
export declare const STATUSES: IntDict;
|
|
8
|
+
export declare const FINISH: IntDict;
|
|
9
|
+
export declare const HEADER_STATE: IntDict;
|
|
10
|
+
export declare const METHODS_HTTP: number[];
|
|
11
|
+
export declare const METHODS_ICE: number[];
|
|
12
|
+
export declare const METHODS_RTSP: number[];
|
|
13
|
+
export declare const METHOD_MAP: IntDict;
|
|
14
|
+
export declare const H_METHOD_MAP: {
|
|
15
|
+
[k: string]: number;
|
|
16
|
+
};
|
|
17
|
+
export declare const STATUSES_HTTP: number[];
|
|
18
|
+
export type CharList = Array<string | number>;
|
|
19
|
+
export declare const ALPHA: CharList;
|
|
20
|
+
export declare const NUM_MAP: {
|
|
21
|
+
0: number;
|
|
22
|
+
1: number;
|
|
23
|
+
2: number;
|
|
24
|
+
3: number;
|
|
25
|
+
4: number;
|
|
26
|
+
5: number;
|
|
27
|
+
6: number;
|
|
28
|
+
7: number;
|
|
29
|
+
8: number;
|
|
30
|
+
9: number;
|
|
31
|
+
};
|
|
32
|
+
export declare const HEX_MAP: {
|
|
33
|
+
0: number;
|
|
34
|
+
1: number;
|
|
35
|
+
2: number;
|
|
36
|
+
3: number;
|
|
37
|
+
4: number;
|
|
38
|
+
5: number;
|
|
39
|
+
6: number;
|
|
40
|
+
7: number;
|
|
41
|
+
8: number;
|
|
42
|
+
9: number;
|
|
43
|
+
A: number;
|
|
44
|
+
B: number;
|
|
45
|
+
C: number;
|
|
46
|
+
D: number;
|
|
47
|
+
E: number;
|
|
48
|
+
F: number;
|
|
49
|
+
a: number;
|
|
50
|
+
b: number;
|
|
51
|
+
c: number;
|
|
52
|
+
d: number;
|
|
53
|
+
e: number;
|
|
54
|
+
f: number;
|
|
55
|
+
};
|
|
56
|
+
export declare const NUM: CharList;
|
|
57
|
+
export declare const ALPHANUM: CharList;
|
|
58
|
+
export declare const MARK: CharList;
|
|
59
|
+
export declare const USERINFO_CHARS: CharList;
|
|
60
|
+
export declare const URL_CHAR: CharList;
|
|
61
|
+
export declare const HEX: CharList;
|
|
62
|
+
export declare const TOKEN: CharList;
|
|
63
|
+
export declare const HEADER_CHARS: CharList;
|
|
64
|
+
export declare const CONNECTION_TOKEN_CHARS: CharList;
|
|
65
|
+
export declare const QUOTED_STRING: CharList;
|
|
66
|
+
export declare const HTAB_SP_VCHAR_OBS_TEXT: CharList;
|
|
67
|
+
export declare const MAJOR: {
|
|
68
|
+
0: number;
|
|
69
|
+
1: number;
|
|
70
|
+
2: number;
|
|
71
|
+
3: number;
|
|
72
|
+
4: number;
|
|
73
|
+
5: number;
|
|
74
|
+
6: number;
|
|
75
|
+
7: number;
|
|
76
|
+
8: number;
|
|
77
|
+
9: number;
|
|
78
|
+
};
|
|
79
|
+
export declare const MINOR: {
|
|
80
|
+
0: number;
|
|
81
|
+
1: number;
|
|
82
|
+
2: number;
|
|
83
|
+
3: number;
|
|
84
|
+
4: number;
|
|
85
|
+
5: number;
|
|
86
|
+
6: number;
|
|
87
|
+
7: number;
|
|
88
|
+
8: number;
|
|
89
|
+
9: number;
|
|
90
|
+
};
|
|
91
|
+
export declare const SPECIAL_HEADERS: {
|
|
92
|
+
connection: number;
|
|
93
|
+
'content-length': number;
|
|
94
|
+
'proxy-connection': number;
|
|
95
|
+
'transfer-encoding': number;
|
|
96
|
+
upgrade: number;
|
|
97
|
+
};
|