@wiajs/req 1.7.28 → 1.7.30
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/dist/node/req.cjs +124 -119
- package/dist/req.js +66 -63
- package/dist/req.min.js +3 -3
- package/dist/web/req.cjs +1911 -2397
- package/dist/web/req.mjs +1917 -2421
- package/lib/adapters/http.js +48 -40
- package/lib/adapters/xhr.js +3 -3
- package/lib/cancel/CancelToken.js +40 -40
- package/lib/core/Axios.js +11 -11
- package/lib/core/AxiosHeaders.js +3 -3
- package/lib/core/InterceptorManager.js +3 -3
- package/lib/helpers/AxiosTransformStream.js +34 -34
- package/lib/helpers/formDataToStream.js +18 -18
- package/lib/platform/node/classes/URLSearchParams.js +1 -1
- package/package.json +226 -214
package/lib/adapters/http.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
import request from '@wiajs/request';
|
|
2
1
|
import { Agent } from '@wiajs/agent';
|
|
3
2
|
import { log as Log, name } from '@wiajs/log';
|
|
4
|
-
import
|
|
5
|
-
import settle from '../core/settle.js';
|
|
3
|
+
import request from '@wiajs/request';
|
|
6
4
|
import buildFullPath from '../core/buildFullPath.js';
|
|
5
|
+
import settle from '../core/settle.js';
|
|
7
6
|
import buildURL from '../helpers/buildURL.js';
|
|
7
|
+
import utils from '../utils.js';
|
|
8
8
|
// import {getProxyForUrl} from 'proxy-from-env';
|
|
9
|
-
import util from '
|
|
9
|
+
import util from 'util';
|
|
10
10
|
// import followRedirects from 'follow-redirects';
|
|
11
11
|
// import Redirect from '../request/index.js'
|
|
12
|
-
import
|
|
13
|
-
import
|
|
14
|
-
import
|
|
15
|
-
import AxiosError from '../core/AxiosError.js';
|
|
12
|
+
import { EventEmitter } from 'events';
|
|
13
|
+
import stream from 'stream';
|
|
14
|
+
import zlib from 'zlib';
|
|
16
15
|
import CanceledError from '../cancel/CanceledError.js';
|
|
17
|
-
import
|
|
18
|
-
import fromDataURI from '../helpers/fromDataURI.js';
|
|
19
|
-
import stream from 'node:stream';
|
|
16
|
+
import AxiosError from '../core/AxiosError.js';
|
|
20
17
|
import AxiosHeaders from '../core/AxiosHeaders.js';
|
|
18
|
+
import transitionalDefaults from '../defaults/transitional.js';
|
|
19
|
+
import { VERSION } from '../env/data.js';
|
|
21
20
|
import AxiosTransformStream from '../helpers/AxiosTransformStream.js';
|
|
22
|
-
import
|
|
21
|
+
import callbackify from '../helpers/callbackify.js';
|
|
23
22
|
import formDataToStream from '../helpers/formDataToStream.js';
|
|
23
|
+
import fromDataURI from '../helpers/fromDataURI.js';
|
|
24
|
+
import { asyncDecorator, progressEventDecorator, progressEventReducer } from '../helpers/progressEventReducer.js';
|
|
24
25
|
import readBlob from '../helpers/readBlob.js';
|
|
25
|
-
import
|
|
26
|
-
import { progressEventReducer, progressEventDecorator, asyncDecorator } from '../helpers/progressEventReducer.js';
|
|
26
|
+
import platform from '../platform/index.js';
|
|
27
27
|
const px = {
|
|
28
28
|
host: '114.98.163.61:17813'
|
|
29
29
|
};
|
|
@@ -47,25 +47,11 @@ const supportedProtocols = platform.protocols.map((protocol)=>`${protocol}:`);
|
|
|
47
47
|
const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(process) === 'process';
|
|
48
48
|
/**
|
|
49
49
|
* !+++
|
|
50
|
-
* 将request
|
|
50
|
+
* 将request 函数改为类,request 拆分为 init 初始化和 请求执行,
|
|
51
51
|
* 如需重新发起请求时,无需重新初始化
|
|
52
52
|
*/ let HttpAdapter = class HttpAdapter {
|
|
53
53
|
/**
|
|
54
54
|
*
|
|
55
|
-
* @param {*} config
|
|
56
|
-
*/ constructor(config){
|
|
57
|
-
this.isDone = false;
|
|
58
|
-
this.rejected = false;
|
|
59
|
-
/** @type {*} */ this.req = null;
|
|
60
|
-
/** @type {*} */ this.config = null;
|
|
61
|
-
/** @type {*} */ this.data = null;
|
|
62
|
-
/** @type {*} */ this.transport = null;
|
|
63
|
-
this.config = config;
|
|
64
|
-
// temporary internal emitter until the AxiosRequest class will be implemented
|
|
65
|
-
this.emitter = new EventEmitter();
|
|
66
|
-
}
|
|
67
|
-
/**
|
|
68
|
-
*
|
|
69
55
|
* @param {number} code
|
|
70
56
|
* @returns
|
|
71
57
|
*/ noBody(code) {
|
|
@@ -81,10 +67,11 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
|
|
|
81
67
|
this.emitter.emit('abort', !reason || reason.type ? new CanceledError(null, this.config, this.req) : reason);
|
|
82
68
|
}
|
|
83
69
|
onFinished() {
|
|
70
|
+
var _config_cancelToken, _config_signal;
|
|
84
71
|
const { config, emitter, abort } = this;
|
|
85
|
-
config
|
|
86
|
-
config
|
|
87
|
-
emitter
|
|
72
|
+
config == null ? void 0 : (_config_cancelToken = config.cancelToken) == null ? void 0 : _config_cancelToken.unsubscribe(abort);
|
|
73
|
+
config == null ? void 0 : (_config_signal = config.signal) == null ? void 0 : _config_signal.removeEventListener('abort', abort);
|
|
74
|
+
emitter == null ? void 0 : emitter.removeAllListeners();
|
|
88
75
|
}
|
|
89
76
|
/**
|
|
90
77
|
*
|
|
@@ -103,9 +90,10 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
|
|
|
103
90
|
* @param {*} isRejected
|
|
104
91
|
* @returns
|
|
105
92
|
*/ done(value, isRejected) {
|
|
93
|
+
var _this;
|
|
106
94
|
if (this.isDone) return;
|
|
107
95
|
this.isDone = true;
|
|
108
|
-
this
|
|
96
|
+
(_this = this) == null ? void 0 : _this.onDone(value, isRejected);
|
|
109
97
|
}
|
|
110
98
|
/**
|
|
111
99
|
* 初始化,生成 options 供请求调用
|
|
@@ -137,7 +125,8 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
|
|
|
137
125
|
};
|
|
138
126
|
}
|
|
139
127
|
if (config.cancelToken || config.signal) {
|
|
140
|
-
|
|
128
|
+
var _config_cancelToken;
|
|
129
|
+
(_config_cancelToken = config.cancelToken) == null ? void 0 : _config_cancelToken.subscribe(_.abort);
|
|
141
130
|
if (config.signal) {
|
|
142
131
|
if (config.signal.aborted) _.abort();
|
|
143
132
|
else config.signal.addEventListener('abort', _.abort);
|
|
@@ -179,7 +168,7 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
|
|
|
179
168
|
const userBoundary = headers.getContentType(/boundary=([-_\w\d]{10,70})/i);
|
|
180
169
|
data = formDataToStream(data, /** @param {*} formHeaders */ (formHeaders)=>headers.set(formHeaders), {
|
|
181
170
|
tag: `axios-${VERSION}-boundary`,
|
|
182
|
-
boundary: userBoundary
|
|
171
|
+
boundary: (userBoundary == null ? void 0 : userBoundary[1]) || undefined
|
|
183
172
|
});
|
|
184
173
|
// support for https://www.npmjs.com/package/form-data api
|
|
185
174
|
} else if (utils.isFormData(data) && utils.isFunction(data.getHeaders)) {
|
|
@@ -289,13 +278,15 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
|
|
|
289
278
|
_.transport = config.transport;
|
|
290
279
|
if (config.maxBodyLength > -1) options.maxBodyLength = config.maxBodyLength;
|
|
291
280
|
else options.maxBodyLength = Number.POSITIVE_INFINITY;
|
|
281
|
+
var _config_maxRedirects;
|
|
292
282
|
// maxRedirects 缺省 21,不跳转,直接使用系统http or https,不支持 stream
|
|
293
283
|
// if (config.maxRedirects === 0 && !config.stream) transport = isHttpsRequest ? https : http;
|
|
294
284
|
// 自动跳转
|
|
295
285
|
// else {
|
|
296
286
|
// 支持跳转或stream,需使用 http、https 封装类
|
|
297
|
-
options.maxRedirects = config.maxRedirects
|
|
298
|
-
|
|
287
|
+
options.maxRedirects = (_config_maxRedirects = config.maxRedirects) != null ? _config_maxRedirects : 21;
|
|
288
|
+
var _config_followRedirects;
|
|
289
|
+
options.followRedirects = (_config_followRedirects = config.followRedirects) != null ? _config_followRedirects : true // 默认自动跳转
|
|
299
290
|
;
|
|
300
291
|
if (config.maxRedirects === 0) options.followRedirects = false;
|
|
301
292
|
if (config.beforeRedirect) options.beforeRedirects.config = config.beforeRedirect;
|
|
@@ -324,8 +315,9 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
|
|
|
324
315
|
if (protocol === 'data:') {
|
|
325
316
|
/** @type {*} */ let convertedData;
|
|
326
317
|
try {
|
|
318
|
+
var _config_env;
|
|
327
319
|
convertedData = fromDataURI(config.url, responseType === 'blob', {
|
|
328
|
-
Blob: config.env
|
|
320
|
+
Blob: (_config_env = config.env) == null ? void 0 : _config_env.Blob
|
|
329
321
|
});
|
|
330
322
|
} catch (err) {
|
|
331
323
|
throw AxiosError.from(err, AxiosError.ERR_BAD_REQUEST, config);
|
|
@@ -358,8 +350,10 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
|
|
|
358
350
|
// 发起异步请求
|
|
359
351
|
R = await new Promise((resolve, reject)=>{
|
|
360
352
|
_.emitter.once('abort', reject);
|
|
361
|
-
|
|
362
|
-
options.
|
|
353
|
+
var _config_stream;
|
|
354
|
+
options.stream = (_config_stream = config.stream) != null ? _config_stream : false;
|
|
355
|
+
var _config_decompress;
|
|
356
|
+
options.decompress = (_config_decompress = config.decompress) != null ? _config_decompress : true;
|
|
363
357
|
// Create the request,promise false: return stream
|
|
364
358
|
// log.debug('request', {options});
|
|
365
359
|
const req = transport ? transport.request(options) : request(options);
|
|
@@ -524,6 +518,20 @@ const isHttpAdapterSupported = typeof process !== 'undefined' && utils.kindOf(pr
|
|
|
524
518
|
}
|
|
525
519
|
return R;
|
|
526
520
|
}
|
|
521
|
+
/**
|
|
522
|
+
*
|
|
523
|
+
* @param {*} config
|
|
524
|
+
*/ constructor(config){
|
|
525
|
+
this.isDone = false;
|
|
526
|
+
this.rejected = false;
|
|
527
|
+
/** @type {*} */ this.req = null;
|
|
528
|
+
/** @type {*} */ this.config = null;
|
|
529
|
+
/** @type {*} */ this.data = null;
|
|
530
|
+
/** @type {*} */ this.transport = null;
|
|
531
|
+
this.config = config;
|
|
532
|
+
// temporary internal emitter until the AxiosRequest class will be implemented
|
|
533
|
+
this.emitter = new EventEmitter();
|
|
534
|
+
}
|
|
527
535
|
};
|
|
528
536
|
/**
|
|
529
537
|
* 排除对象字段
|
package/lib/adapters/xhr.js
CHANGED
|
@@ -36,12 +36,12 @@ function progressEventReducer(listener, isDownloadStream) {
|
|
|
36
36
|
}
|
|
37
37
|
const isXHRAdapterSupported = typeof XMLHttpRequest !== 'undefined';
|
|
38
38
|
let XhrAdapter = class XhrAdapter {
|
|
39
|
-
constructor(config){
|
|
40
|
-
this.init(config);
|
|
41
|
-
}
|
|
42
39
|
init(config) {}
|
|
43
40
|
request() {}
|
|
44
41
|
stream() {}
|
|
42
|
+
constructor(config){
|
|
43
|
+
this.init(config);
|
|
44
|
+
}
|
|
45
45
|
};
|
|
46
46
|
export default isXHRAdapterSupported && XhrAdapter;
|
|
47
47
|
function req(config) {
|
|
@@ -7,46 +7,6 @@ import CanceledError from './CanceledError.js';
|
|
|
7
7
|
*
|
|
8
8
|
* @returns {CancelToken}
|
|
9
9
|
*/ let CancelToken = class CancelToken {
|
|
10
|
-
constructor(executor){
|
|
11
|
-
if (typeof executor !== 'function') {
|
|
12
|
-
throw new TypeError('executor must be a function.');
|
|
13
|
-
}
|
|
14
|
-
let resolvePromise;
|
|
15
|
-
this.promise = new Promise(function promiseExecutor(resolve) {
|
|
16
|
-
resolvePromise = resolve;
|
|
17
|
-
});
|
|
18
|
-
const token = this;
|
|
19
|
-
// eslint-disable-next-line func-names
|
|
20
|
-
this.promise.then((cancel)=>{
|
|
21
|
-
if (!token._listeners) return;
|
|
22
|
-
let i = token._listeners.length;
|
|
23
|
-
while(i-- > 0){
|
|
24
|
-
token._listeners[i](cancel);
|
|
25
|
-
}
|
|
26
|
-
token._listeners = null;
|
|
27
|
-
});
|
|
28
|
-
// eslint-disable-next-line func-names
|
|
29
|
-
this.promise.then = (onfulfilled)=>{
|
|
30
|
-
let _resolve;
|
|
31
|
-
// eslint-disable-next-line func-names
|
|
32
|
-
const promise = new Promise((resolve)=>{
|
|
33
|
-
token.subscribe(resolve);
|
|
34
|
-
_resolve = resolve;
|
|
35
|
-
}).then(onfulfilled);
|
|
36
|
-
promise.cancel = function reject() {
|
|
37
|
-
token.unsubscribe(_resolve);
|
|
38
|
-
};
|
|
39
|
-
return promise;
|
|
40
|
-
};
|
|
41
|
-
executor(function cancel(message, config, request) {
|
|
42
|
-
if (token.reason) {
|
|
43
|
-
// Cancellation has already been requested
|
|
44
|
-
return;
|
|
45
|
-
}
|
|
46
|
-
token.reason = new CanceledError(message, config, request);
|
|
47
|
-
resolvePromise(token.reason);
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
10
|
/**
|
|
51
11
|
* Throws a `CanceledError` if cancellation has been requested.
|
|
52
12
|
*/ throwIfRequested() {
|
|
@@ -102,5 +62,45 @@ import CanceledError from './CanceledError.js';
|
|
|
102
62
|
cancel
|
|
103
63
|
};
|
|
104
64
|
}
|
|
65
|
+
constructor(executor){
|
|
66
|
+
if (typeof executor !== 'function') {
|
|
67
|
+
throw new TypeError('executor must be a function.');
|
|
68
|
+
}
|
|
69
|
+
let resolvePromise;
|
|
70
|
+
this.promise = new Promise(function promiseExecutor(resolve) {
|
|
71
|
+
resolvePromise = resolve;
|
|
72
|
+
});
|
|
73
|
+
const token = this;
|
|
74
|
+
// eslint-disable-next-line func-names
|
|
75
|
+
this.promise.then((cancel)=>{
|
|
76
|
+
if (!token._listeners) return;
|
|
77
|
+
let i = token._listeners.length;
|
|
78
|
+
while(i-- > 0){
|
|
79
|
+
token._listeners[i](cancel);
|
|
80
|
+
}
|
|
81
|
+
token._listeners = null;
|
|
82
|
+
});
|
|
83
|
+
// eslint-disable-next-line func-names
|
|
84
|
+
this.promise.then = (onfulfilled)=>{
|
|
85
|
+
let _resolve;
|
|
86
|
+
// eslint-disable-next-line func-names
|
|
87
|
+
const promise = new Promise((resolve)=>{
|
|
88
|
+
token.subscribe(resolve);
|
|
89
|
+
_resolve = resolve;
|
|
90
|
+
}).then(onfulfilled);
|
|
91
|
+
promise.cancel = function reject() {
|
|
92
|
+
token.unsubscribe(_resolve);
|
|
93
|
+
};
|
|
94
|
+
return promise;
|
|
95
|
+
};
|
|
96
|
+
executor(function cancel(message, config, request) {
|
|
97
|
+
if (token.reason) {
|
|
98
|
+
// Cancellation has already been requested
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
token.reason = new CanceledError(message, config, request);
|
|
102
|
+
resolvePromise(token.reason);
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
105
|
};
|
|
106
106
|
export default CancelToken;
|
package/lib/core/Axios.js
CHANGED
|
@@ -14,17 +14,6 @@ const { validators } = validator;
|
|
|
14
14
|
*
|
|
15
15
|
* @return {Axios} A new instance of Axios
|
|
16
16
|
*/ let Axios = class Axios {
|
|
17
|
-
constructor(instanceConfig){
|
|
18
|
-
this.defaults = instanceConfig;
|
|
19
|
-
this.config = this.defaults // !+++
|
|
20
|
-
;
|
|
21
|
-
this.interceptors = {
|
|
22
|
-
request: new InterceptorManager(),
|
|
23
|
-
response: new InterceptorManager()
|
|
24
|
-
};
|
|
25
|
-
this.init() // !+++
|
|
26
|
-
;
|
|
27
|
-
}
|
|
28
17
|
/**
|
|
29
18
|
* !+++
|
|
30
19
|
* config 属性直接挂在到实例上,方便读取、设置、修改
|
|
@@ -275,6 +264,17 @@ const { validators } = validator;
|
|
|
275
264
|
const fullPath = buildFullPath(config.baseURL, config.url);
|
|
276
265
|
return buildURL(fullPath, config.params, config.paramsSerializer);
|
|
277
266
|
}
|
|
267
|
+
constructor(instanceConfig){
|
|
268
|
+
this.defaults = instanceConfig;
|
|
269
|
+
this.config = this.defaults // !+++
|
|
270
|
+
;
|
|
271
|
+
this.interceptors = {
|
|
272
|
+
request: new InterceptorManager(),
|
|
273
|
+
response: new InterceptorManager()
|
|
274
|
+
};
|
|
275
|
+
this.init() // !+++
|
|
276
|
+
;
|
|
277
|
+
}
|
|
278
278
|
};
|
|
279
279
|
// Provide aliases for supported request methods
|
|
280
280
|
utils.forEach([
|
package/lib/core/AxiosHeaders.js
CHANGED
|
@@ -59,9 +59,6 @@ function buildAccessors(obj, header) {
|
|
|
59
59
|
}
|
|
60
60
|
_computedKey = Symbol.iterator, _computedKey1 = Symbol.toStringTag;
|
|
61
61
|
let AxiosHeaders = class AxiosHeaders {
|
|
62
|
-
constructor(headers){
|
|
63
|
-
headers && this.set(headers);
|
|
64
|
-
}
|
|
65
62
|
/**
|
|
66
63
|
*
|
|
67
64
|
* @param {*} header
|
|
@@ -220,6 +217,9 @@ let AxiosHeaders = class AxiosHeaders {
|
|
|
220
217
|
utils.isArray(header) ? header.forEach(defineAccessor) : defineAccessor(header);
|
|
221
218
|
return this;
|
|
222
219
|
}
|
|
220
|
+
constructor(headers){
|
|
221
|
+
headers && this.set(headers);
|
|
222
|
+
}
|
|
223
223
|
};
|
|
224
224
|
AxiosHeaders.accessor([
|
|
225
225
|
'Content-Type',
|
|
@@ -1,8 +1,5 @@
|
|
|
1
1
|
import utils from '../utils.js';
|
|
2
2
|
let InterceptorManager = class InterceptorManager {
|
|
3
|
-
constructor(){
|
|
4
|
-
this.handlers = [];
|
|
5
|
-
}
|
|
6
3
|
/**
|
|
7
4
|
* Add a new interceptor to the stack
|
|
8
5
|
*
|
|
@@ -55,5 +52,8 @@ let InterceptorManager = class InterceptorManager {
|
|
|
55
52
|
}
|
|
56
53
|
});
|
|
57
54
|
}
|
|
55
|
+
constructor(){
|
|
56
|
+
this.handlers = [];
|
|
57
|
+
}
|
|
58
58
|
};
|
|
59
59
|
export default InterceptorManager;
|
|
@@ -3,40 +3,6 @@ import stream from 'stream';
|
|
|
3
3
|
import utils from '../utils.js';
|
|
4
4
|
const kInternals = Symbol('internals');
|
|
5
5
|
let AxiosTransformStream = class AxiosTransformStream extends stream.Transform {
|
|
6
|
-
constructor(options){
|
|
7
|
-
options = utils.toFlatObject(options, {
|
|
8
|
-
maxRate: 0,
|
|
9
|
-
chunkSize: 64 * 1024,
|
|
10
|
-
minChunkSize: 100,
|
|
11
|
-
timeWindow: 500,
|
|
12
|
-
ticksRate: 2,
|
|
13
|
-
samplesCount: 15
|
|
14
|
-
}, null, (prop, source)=>{
|
|
15
|
-
return !utils.isUndefined(source[prop]);
|
|
16
|
-
});
|
|
17
|
-
super({
|
|
18
|
-
readableHighWaterMark: options.chunkSize
|
|
19
|
-
});
|
|
20
|
-
const internals = this[kInternals] = {
|
|
21
|
-
timeWindow: options.timeWindow,
|
|
22
|
-
chunkSize: options.chunkSize,
|
|
23
|
-
maxRate: options.maxRate,
|
|
24
|
-
minChunkSize: options.minChunkSize,
|
|
25
|
-
bytesSeen: 0,
|
|
26
|
-
isCaptured: false,
|
|
27
|
-
notifiedBytesLoaded: 0,
|
|
28
|
-
ts: Date.now(),
|
|
29
|
-
bytes: 0,
|
|
30
|
-
onReadCallback: null
|
|
31
|
-
};
|
|
32
|
-
this.on('newListener', (event)=>{
|
|
33
|
-
if (event === 'progress') {
|
|
34
|
-
if (!internals.isCaptured) {
|
|
35
|
-
internals.isCaptured = true;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
});
|
|
39
|
-
}
|
|
40
6
|
_read(size) {
|
|
41
7
|
const internals = this[kInternals];
|
|
42
8
|
if (internals.onReadCallback) {
|
|
@@ -112,5 +78,39 @@ let AxiosTransformStream = class AxiosTransformStream extends stream.Transform {
|
|
|
112
78
|
}
|
|
113
79
|
});
|
|
114
80
|
}
|
|
81
|
+
constructor(options){
|
|
82
|
+
options = utils.toFlatObject(options, {
|
|
83
|
+
maxRate: 0,
|
|
84
|
+
chunkSize: 64 * 1024,
|
|
85
|
+
minChunkSize: 100,
|
|
86
|
+
timeWindow: 500,
|
|
87
|
+
ticksRate: 2,
|
|
88
|
+
samplesCount: 15
|
|
89
|
+
}, null, (prop, source)=>{
|
|
90
|
+
return !utils.isUndefined(source[prop]);
|
|
91
|
+
});
|
|
92
|
+
super({
|
|
93
|
+
readableHighWaterMark: options.chunkSize
|
|
94
|
+
});
|
|
95
|
+
const internals = this[kInternals] = {
|
|
96
|
+
timeWindow: options.timeWindow,
|
|
97
|
+
chunkSize: options.chunkSize,
|
|
98
|
+
maxRate: options.maxRate,
|
|
99
|
+
minChunkSize: options.minChunkSize,
|
|
100
|
+
bytesSeen: 0,
|
|
101
|
+
isCaptured: false,
|
|
102
|
+
notifiedBytesLoaded: 0,
|
|
103
|
+
ts: Date.now(),
|
|
104
|
+
bytes: 0,
|
|
105
|
+
onReadCallback: null
|
|
106
|
+
};
|
|
107
|
+
this.on('newListener', (event)=>{
|
|
108
|
+
if (event === 'progress') {
|
|
109
|
+
if (!internals.isCaptured) {
|
|
110
|
+
internals.isCaptured = true;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
115
|
};
|
|
116
116
|
export default AxiosTransformStream;
|
|
@@ -1,28 +1,13 @@
|
|
|
1
|
-
import { TextEncoder } from 'node:util';
|
|
2
1
|
import { Readable } from 'stream';
|
|
3
|
-
import
|
|
4
|
-
import
|
|
2
|
+
import { TextEncoder } from 'util';
|
|
3
|
+
import utils from '../utils.js';
|
|
4
|
+
import readBlob from './readBlob.js';
|
|
5
5
|
const BOUNDARY_ALPHABET = utils.ALPHABET.ALPHA_DIGIT + '-_';
|
|
6
6
|
const textEncoder = new TextEncoder();
|
|
7
7
|
const CRLF = '\r\n';
|
|
8
8
|
const CRLF_BYTES = textEncoder.encode(CRLF);
|
|
9
9
|
const CRLF_BYTES_COUNT = 2;
|
|
10
10
|
let FormDataPart = class FormDataPart {
|
|
11
|
-
constructor(name, value){
|
|
12
|
-
const { escapeName } = this.constructor;
|
|
13
|
-
const isStringValue = utils.isString(value);
|
|
14
|
-
let headers = `Content-Disposition: form-data; name="${escapeName(name)}"${!isStringValue && value.name ? `; filename="${escapeName(value.name)}"` : ''}${CRLF}`;
|
|
15
|
-
if (isStringValue) {
|
|
16
|
-
value = textEncoder.encode(String(value).replace(/\r?\n|\r\n?/g, CRLF));
|
|
17
|
-
} else {
|
|
18
|
-
headers += `Content-Type: ${value.type || "application/octet-stream"}${CRLF}`;
|
|
19
|
-
}
|
|
20
|
-
this.headers = textEncoder.encode(headers + CRLF);
|
|
21
|
-
this.contentLength = isStringValue ? value.byteLength : value.size;
|
|
22
|
-
this.size = this.headers.byteLength + this.contentLength + CRLF_BYTES_COUNT;
|
|
23
|
-
this.name = name;
|
|
24
|
-
this.value = value;
|
|
25
|
-
}
|
|
26
11
|
async *encode() {
|
|
27
12
|
yield this.headers;
|
|
28
13
|
const { value } = this;
|
|
@@ -40,6 +25,21 @@ let FormDataPart = class FormDataPart {
|
|
|
40
25
|
'"': '%22'
|
|
41
26
|
})[match]);
|
|
42
27
|
}
|
|
28
|
+
constructor(name, value){
|
|
29
|
+
const { escapeName } = this.constructor;
|
|
30
|
+
const isStringValue = utils.isString(value);
|
|
31
|
+
let headers = `Content-Disposition: form-data; name="${escapeName(name)}"${!isStringValue && value.name ? `; filename="${escapeName(value.name)}"` : ''}${CRLF}`;
|
|
32
|
+
if (isStringValue) {
|
|
33
|
+
value = textEncoder.encode(String(value).replace(/\r?\n|\r\n?/g, CRLF));
|
|
34
|
+
} else {
|
|
35
|
+
headers += `Content-Type: ${value.type || 'application/octet-stream'}${CRLF}`;
|
|
36
|
+
}
|
|
37
|
+
this.headers = textEncoder.encode(headers + CRLF);
|
|
38
|
+
this.contentLength = isStringValue ? value.byteLength : value.size;
|
|
39
|
+
this.size = this.headers.byteLength + this.contentLength + CRLF_BYTES_COUNT;
|
|
40
|
+
this.name = name;
|
|
41
|
+
this.value = value;
|
|
42
|
+
}
|
|
43
43
|
};
|
|
44
44
|
const formDataToStream = (form, headersHandler, options)=>{
|
|
45
45
|
const { tag = 'form-data-boundary', size = 25, boundary = tag + '-' + utils.generateString(size, BOUNDARY_ALPHABET) } = options || {};
|