cdk-common 2.0.1233 → 2.0.1235
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/.jsii +32 -2
- package/API.md +30 -0
- package/lib/main.js +1 -1
- package/lib/managed-policies.d.ts +6 -1
- package/lib/managed-policies.js +6 -1
- package/node_modules/form-data/CHANGELOG.md +644 -0
- package/node_modules/form-data/{Readme.md → README.md} +4 -4
- package/node_modules/form-data/README.md.bak +350 -0
- package/node_modules/form-data/lib/browser.js +3 -1
- package/node_modules/form-data/lib/form_data.js +150 -127
- package/node_modules/form-data/lib/populate.js +4 -4
- package/node_modules/form-data/package.json +24 -17
- package/node_modules/has-own/.travis.yml +4 -0
- package/node_modules/has-own/History.md +5 -0
- package/node_modules/has-own/LICENSE +22 -0
- package/node_modules/has-own/Makefile +5 -0
- package/node_modules/has-own/README.md +19 -0
- package/node_modules/has-own/index.js +8 -0
- package/node_modules/has-own/package.json +19 -0
- package/node_modules/has-own/test/index.js +36 -0
- package/package.json +1 -1
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
1
3
|
var CombinedStream = require('combined-stream');
|
|
2
4
|
var util = require('util');
|
|
3
5
|
var path = require('path');
|
|
@@ -5,17 +7,13 @@ var http = require('http');
|
|
|
5
7
|
var https = require('https');
|
|
6
8
|
var parseUrl = require('url').parse;
|
|
7
9
|
var fs = require('fs');
|
|
10
|
+
var crypto = require('crypto');
|
|
8
11
|
var mime = require('mime-types');
|
|
9
12
|
var asynckit = require('asynckit');
|
|
13
|
+
var hasOwn = require('hasown');
|
|
10
14
|
var setToStringTag = require('es-set-tostringtag');
|
|
11
15
|
var populate = require('./populate.js');
|
|
12
|
-
var Buffer = require('safe-buffer').Buffer;
|
|
13
|
-
|
|
14
|
-
// Public API
|
|
15
|
-
module.exports = FormData;
|
|
16
|
-
|
|
17
|
-
// make it a Stream
|
|
18
|
-
util.inherits(FormData, CombinedStream);
|
|
16
|
+
var Buffer = require('safe-buffer').Buffer;
|
|
19
17
|
|
|
20
18
|
/**
|
|
21
19
|
* Create readable "multipart/form-data" streams.
|
|
@@ -37,34 +35,39 @@ function FormData(options) {
|
|
|
37
35
|
CombinedStream.call(this);
|
|
38
36
|
|
|
39
37
|
options = options || {};
|
|
40
|
-
for (var option in options) {
|
|
38
|
+
for (var option in options) { // eslint-disable-line no-restricted-syntax
|
|
41
39
|
this[option] = options[option];
|
|
42
40
|
}
|
|
43
41
|
}
|
|
44
42
|
|
|
43
|
+
// make it a Stream
|
|
44
|
+
util.inherits(FormData, CombinedStream);
|
|
45
|
+
|
|
45
46
|
FormData.LINE_BREAK = '\r\n';
|
|
46
47
|
FormData.DEFAULT_CONTENT_TYPE = 'application/octet-stream';
|
|
47
48
|
|
|
48
|
-
FormData.prototype.append = function(field, value, options) {
|
|
49
|
+
FormData.prototype.append = function (field, value, options) {
|
|
49
50
|
|
|
50
51
|
options = options || {};
|
|
51
52
|
|
|
52
53
|
// allow filename as single option
|
|
53
|
-
if (typeof options
|
|
54
|
-
options = {filename: options};
|
|
54
|
+
if (typeof options === 'string') {
|
|
55
|
+
options = { filename: options };
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
var append = CombinedStream.prototype.append.bind(this);
|
|
58
59
|
|
|
59
60
|
// all that streamy business can't handle numbers
|
|
60
|
-
if (typeof value
|
|
61
|
-
value =
|
|
61
|
+
if (typeof value === 'number' || value == null) {
|
|
62
|
+
value = String(value);
|
|
62
63
|
}
|
|
63
64
|
|
|
64
65
|
// https://github.com/felixge/node-form-data/issues/38
|
|
65
66
|
if (Array.isArray(value)) {
|
|
66
|
-
|
|
67
|
-
|
|
67
|
+
/*
|
|
68
|
+
* Please convert your array into string
|
|
69
|
+
* the way web server expects it
|
|
70
|
+
*/
|
|
68
71
|
this._error(new Error('Arrays are not supported.'));
|
|
69
72
|
return;
|
|
70
73
|
}
|
|
@@ -80,15 +83,17 @@ FormData.prototype.append = function(field, value, options) {
|
|
|
80
83
|
this._trackLength(header, value, options);
|
|
81
84
|
};
|
|
82
85
|
|
|
83
|
-
FormData.prototype._trackLength = function(header, value, options) {
|
|
86
|
+
FormData.prototype._trackLength = function (header, value, options) {
|
|
84
87
|
var valueLength = 0;
|
|
85
88
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
89
|
+
/*
|
|
90
|
+
* used w/ getLengthSync(), when length is known.
|
|
91
|
+
* e.g. for streaming directly from a remote server,
|
|
92
|
+
* w/ a known file a size, and not wanting to wait for
|
|
93
|
+
* incoming file to finish to get its size.
|
|
94
|
+
*/
|
|
90
95
|
if (options.knownLength != null) {
|
|
91
|
-
valueLength +=
|
|
96
|
+
valueLength += Number(options.knownLength);
|
|
92
97
|
} else if (Buffer.isBuffer(value)) {
|
|
93
98
|
valueLength = value.length;
|
|
94
99
|
} else if (typeof value === 'string') {
|
|
@@ -98,12 +103,10 @@ FormData.prototype._trackLength = function(header, value, options) {
|
|
|
98
103
|
this._valueLength += valueLength;
|
|
99
104
|
|
|
100
105
|
// @check why add CRLF? does this account for custom/multiple CRLFs?
|
|
101
|
-
this._overheadLength +=
|
|
102
|
-
Buffer.byteLength(header) +
|
|
103
|
-
FormData.LINE_BREAK.length;
|
|
106
|
+
this._overheadLength += Buffer.byteLength(header) + FormData.LINE_BREAK.length;
|
|
104
107
|
|
|
105
108
|
// empty or either doesn't have path or not an http response
|
|
106
|
-
if (!value || (
|
|
109
|
+
if (!value || (!value.path && !(value.readable && hasOwn(value, 'httpVersion')))) {
|
|
107
110
|
return;
|
|
108
111
|
}
|
|
109
112
|
|
|
@@ -113,27 +116,31 @@ FormData.prototype._trackLength = function(header, value, options) {
|
|
|
113
116
|
}
|
|
114
117
|
};
|
|
115
118
|
|
|
116
|
-
FormData.prototype._lengthRetriever = function(value, callback) {
|
|
117
|
-
if (
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
119
|
+
FormData.prototype._lengthRetriever = function (value, callback) {
|
|
120
|
+
if (hasOwn(value, 'fd')) {
|
|
121
|
+
|
|
122
|
+
/*
|
|
123
|
+
* take read range into a account
|
|
124
|
+
* `end` = Infinity –> read file till the end
|
|
125
|
+
*
|
|
126
|
+
* TODO: Looks like there is bug in Node fs.createReadStream
|
|
127
|
+
* it doesn't respect `end` options without `start` options
|
|
128
|
+
* Fix it when node fixes it.
|
|
129
|
+
* https://github.com/joyent/node/issues/7819
|
|
130
|
+
*/
|
|
131
|
+
if (value.end != null && value.end !== Infinity && value.start != null) {
|
|
132
|
+
|
|
133
|
+
/*
|
|
134
|
+
* when end specified
|
|
135
|
+
* no need to calculate range
|
|
136
|
+
* inclusive, starts with 0
|
|
137
|
+
*/
|
|
131
138
|
callback(null, value.end + 1 - (value.start ? value.start : 0));
|
|
132
139
|
|
|
133
140
|
// not that fast snoopy
|
|
134
141
|
} else {
|
|
135
142
|
// still need to fetch file size from fs
|
|
136
|
-
fs.stat(value.path, function(err, stat) {
|
|
143
|
+
fs.stat(value.path, function (err, stat) {
|
|
137
144
|
|
|
138
145
|
var fileSize;
|
|
139
146
|
|
|
@@ -149,15 +156,15 @@ FormData.prototype._lengthRetriever = function(value, callback) {
|
|
|
149
156
|
}
|
|
150
157
|
|
|
151
158
|
// or http response
|
|
152
|
-
} else if (
|
|
153
|
-
callback(null,
|
|
159
|
+
} else if (hasOwn(value, 'httpVersion')) {
|
|
160
|
+
callback(null, Number(value.headers['content-length']));
|
|
154
161
|
|
|
155
162
|
// or request stream http://github.com/mikeal/request
|
|
156
|
-
} else if (
|
|
163
|
+
} else if (hasOwn(value, 'httpModule')) {
|
|
157
164
|
// wait till response come back
|
|
158
|
-
value.on('response', function(response) {
|
|
165
|
+
value.on('response', function (response) {
|
|
159
166
|
value.pause();
|
|
160
|
-
callback(null,
|
|
167
|
+
callback(null, Number(response.headers['content-length']));
|
|
161
168
|
});
|
|
162
169
|
value.resume();
|
|
163
170
|
|
|
@@ -167,11 +174,13 @@ FormData.prototype._lengthRetriever = function(value, callback) {
|
|
|
167
174
|
}
|
|
168
175
|
};
|
|
169
176
|
|
|
170
|
-
FormData.prototype._multiPartHeader = function(field, value, options) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
177
|
+
FormData.prototype._multiPartHeader = function (field, value, options) {
|
|
178
|
+
/*
|
|
179
|
+
* custom header specified (as string)?
|
|
180
|
+
* it becomes responsible for boundary
|
|
181
|
+
* (e.g. to handle extra CRLFs on .NET servers)
|
|
182
|
+
*/
|
|
183
|
+
if (typeof options.header === 'string') {
|
|
175
184
|
return options.header;
|
|
176
185
|
}
|
|
177
186
|
|
|
@@ -179,26 +188,26 @@ FormData.prototype._multiPartHeader = function(field, value, options) {
|
|
|
179
188
|
var contentType = this._getContentType(value, options);
|
|
180
189
|
|
|
181
190
|
var contents = '';
|
|
182
|
-
var headers
|
|
191
|
+
var headers = {
|
|
183
192
|
// add custom disposition as third element or keep it two elements if not
|
|
184
193
|
'Content-Disposition': ['form-data', 'name="' + field + '"'].concat(contentDisposition || []),
|
|
185
194
|
// if no content type. allow it to be empty array
|
|
186
|
-
'Content-Type': [].concat(contentType || [])
|
|
195
|
+
'Content-Type': [].concat(contentType || []),
|
|
187
196
|
};
|
|
188
197
|
|
|
189
198
|
// allow custom headers.
|
|
190
|
-
if (typeof options.header
|
|
199
|
+
if (typeof options.header === 'object') {
|
|
191
200
|
populate(headers, options.header);
|
|
192
201
|
}
|
|
193
202
|
|
|
194
203
|
var header;
|
|
195
|
-
for (var prop in headers) {
|
|
196
|
-
if (
|
|
204
|
+
for (var prop in headers) { // eslint-disable-line no-restricted-syntax
|
|
205
|
+
if (hasOwn(headers, prop)) {
|
|
197
206
|
header = headers[prop];
|
|
198
207
|
|
|
199
208
|
// skip nullish headers.
|
|
200
209
|
if (header == null) {
|
|
201
|
-
continue;
|
|
210
|
+
continue; // eslint-disable-line no-continue, no-restricted-syntax
|
|
202
211
|
}
|
|
203
212
|
|
|
204
213
|
// convert all headers to arrays.
|
|
@@ -216,21 +225,21 @@ FormData.prototype._multiPartHeader = function(field, value, options) {
|
|
|
216
225
|
return '--' + this.getBoundary() + FormData.LINE_BREAK + contents + FormData.LINE_BREAK;
|
|
217
226
|
};
|
|
218
227
|
|
|
219
|
-
FormData.prototype._getContentDisposition = function(value, options) {
|
|
220
|
-
|
|
221
|
-
var filename
|
|
222
|
-
, contentDisposition
|
|
223
|
-
;
|
|
228
|
+
FormData.prototype._getContentDisposition = function (value, options) {
|
|
224
229
|
|
|
230
|
+
var filename,
|
|
231
|
+
contentDisposition;
|
|
225
232
|
if (typeof options.filepath === 'string') {
|
|
226
233
|
// custom filepath for relative paths
|
|
227
234
|
filename = path.normalize(options.filepath).replace(/\\/g, '/');
|
|
228
|
-
} else if (options.filename || value.name || value.path) {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
235
|
+
} else if (options.filename || (value && (value.name || value.path))) {
|
|
236
|
+
/*
|
|
237
|
+
* custom filename take precedence
|
|
238
|
+
* formidable and the browser add a name property
|
|
239
|
+
* fs- and request- streams have path property
|
|
240
|
+
*/
|
|
241
|
+
filename = path.basename(options.filename || (value && (value.name || value.path)));
|
|
242
|
+
} else if (value && value.readable && hasOwn(value, 'httpVersion')) {
|
|
234
243
|
// or try http response
|
|
235
244
|
filename = path.basename(value.client._httpMessage.path || '');
|
|
236
245
|
}
|
|
@@ -242,23 +251,23 @@ FormData.prototype._getContentDisposition = function(value, options) {
|
|
|
242
251
|
return contentDisposition;
|
|
243
252
|
};
|
|
244
253
|
|
|
245
|
-
FormData.prototype._getContentType = function(value, options) {
|
|
254
|
+
FormData.prototype._getContentType = function (value, options) {
|
|
246
255
|
|
|
247
256
|
// use custom content-type above all
|
|
248
257
|
var contentType = options.contentType;
|
|
249
258
|
|
|
250
259
|
// or try `name` from formidable, browser
|
|
251
|
-
if (!contentType && value.name) {
|
|
260
|
+
if (!contentType && value && value.name) {
|
|
252
261
|
contentType = mime.lookup(value.name);
|
|
253
262
|
}
|
|
254
263
|
|
|
255
264
|
// or try `path` from fs-, request- streams
|
|
256
|
-
if (!contentType && value.path) {
|
|
265
|
+
if (!contentType && value && value.path) {
|
|
257
266
|
contentType = mime.lookup(value.path);
|
|
258
267
|
}
|
|
259
268
|
|
|
260
269
|
// or if it's http-reponse
|
|
261
|
-
if (!contentType && value.readable &&
|
|
270
|
+
if (!contentType && value && value.readable && hasOwn(value, 'httpVersion')) {
|
|
262
271
|
contentType = value.headers['content-type'];
|
|
263
272
|
}
|
|
264
273
|
|
|
@@ -268,18 +277,18 @@ FormData.prototype._getContentType = function(value, options) {
|
|
|
268
277
|
}
|
|
269
278
|
|
|
270
279
|
// fallback to the default content type if `value` is not simple value
|
|
271
|
-
if (!contentType && typeof value
|
|
280
|
+
if (!contentType && value && typeof value === 'object') {
|
|
272
281
|
contentType = FormData.DEFAULT_CONTENT_TYPE;
|
|
273
282
|
}
|
|
274
283
|
|
|
275
284
|
return contentType;
|
|
276
285
|
};
|
|
277
286
|
|
|
278
|
-
FormData.prototype._multiPartFooter = function() {
|
|
279
|
-
return function(next) {
|
|
287
|
+
FormData.prototype._multiPartFooter = function () {
|
|
288
|
+
return function (next) {
|
|
280
289
|
var footer = FormData.LINE_BREAK;
|
|
281
290
|
|
|
282
|
-
var lastPart =
|
|
291
|
+
var lastPart = this._streams.length === 0;
|
|
283
292
|
if (lastPart) {
|
|
284
293
|
footer += this._lastBoundary();
|
|
285
294
|
}
|
|
@@ -288,18 +297,18 @@ FormData.prototype._multiPartFooter = function() {
|
|
|
288
297
|
}.bind(this);
|
|
289
298
|
};
|
|
290
299
|
|
|
291
|
-
FormData.prototype._lastBoundary = function() {
|
|
300
|
+
FormData.prototype._lastBoundary = function () {
|
|
292
301
|
return '--' + this.getBoundary() + '--' + FormData.LINE_BREAK;
|
|
293
302
|
};
|
|
294
303
|
|
|
295
|
-
FormData.prototype.getHeaders = function(userHeaders) {
|
|
304
|
+
FormData.prototype.getHeaders = function (userHeaders) {
|
|
296
305
|
var header;
|
|
297
306
|
var formHeaders = {
|
|
298
|
-
'content-type': 'multipart/form-data; boundary=' + this.getBoundary()
|
|
307
|
+
'content-type': 'multipart/form-data; boundary=' + this.getBoundary(),
|
|
299
308
|
};
|
|
300
309
|
|
|
301
|
-
for (header in userHeaders) {
|
|
302
|
-
if (
|
|
310
|
+
for (header in userHeaders) { // eslint-disable-line no-restricted-syntax
|
|
311
|
+
if (hasOwn(userHeaders, header)) {
|
|
303
312
|
formHeaders[header.toLowerCase()] = userHeaders[header];
|
|
304
313
|
}
|
|
305
314
|
}
|
|
@@ -307,7 +316,14 @@ FormData.prototype.getHeaders = function(userHeaders) {
|
|
|
307
316
|
return formHeaders;
|
|
308
317
|
};
|
|
309
318
|
|
|
310
|
-
FormData.prototype.
|
|
319
|
+
FormData.prototype.setBoundary = function (boundary) {
|
|
320
|
+
if (typeof boundary !== 'string') {
|
|
321
|
+
throw new TypeError('FormData boundary must be a string');
|
|
322
|
+
}
|
|
323
|
+
this._boundary = boundary;
|
|
324
|
+
};
|
|
325
|
+
|
|
326
|
+
FormData.prototype.getBoundary = function () {
|
|
311
327
|
if (!this._boundary) {
|
|
312
328
|
this._generateBoundary();
|
|
313
329
|
}
|
|
@@ -315,8 +331,8 @@ FormData.prototype.getBoundary = function() {
|
|
|
315
331
|
return this._boundary;
|
|
316
332
|
};
|
|
317
333
|
|
|
318
|
-
FormData.prototype.getBuffer = function() {
|
|
319
|
-
var dataBuffer =
|
|
334
|
+
FormData.prototype.getBuffer = function () {
|
|
335
|
+
var dataBuffer = Buffer.alloc(0);
|
|
320
336
|
var boundary = this.getBoundary();
|
|
321
337
|
|
|
322
338
|
// Create the form content. Add Line breaks to the end of data.
|
|
@@ -324,61 +340,65 @@ FormData.prototype.getBuffer = function() {
|
|
|
324
340
|
if (typeof this._streams[i] !== 'function') {
|
|
325
341
|
|
|
326
342
|
// Add content to the buffer.
|
|
327
|
-
if(Buffer.isBuffer(this._streams[i])) {
|
|
328
|
-
dataBuffer = Buffer.concat(
|
|
329
|
-
}else {
|
|
330
|
-
dataBuffer = Buffer.concat(
|
|
343
|
+
if (Buffer.isBuffer(this._streams[i])) {
|
|
344
|
+
dataBuffer = Buffer.concat([dataBuffer, this._streams[i]]);
|
|
345
|
+
} else {
|
|
346
|
+
dataBuffer = Buffer.concat([dataBuffer, Buffer.from(this._streams[i])]);
|
|
331
347
|
}
|
|
332
348
|
|
|
333
349
|
// Add break after content.
|
|
334
|
-
if (typeof this._streams[i] !== 'string' || this._streams[i].substring(
|
|
335
|
-
dataBuffer = Buffer.concat(
|
|
350
|
+
if (typeof this._streams[i] !== 'string' || this._streams[i].substring(2, boundary.length + 2) !== boundary) {
|
|
351
|
+
dataBuffer = Buffer.concat([dataBuffer, Buffer.from(FormData.LINE_BREAK)]);
|
|
336
352
|
}
|
|
337
353
|
}
|
|
338
354
|
}
|
|
339
355
|
|
|
340
356
|
// Add the footer and return the Buffer object.
|
|
341
|
-
return Buffer.concat(
|
|
357
|
+
return Buffer.concat([dataBuffer, Buffer.from(this._lastBoundary())]);
|
|
342
358
|
};
|
|
343
359
|
|
|
344
|
-
FormData.prototype._generateBoundary = function() {
|
|
360
|
+
FormData.prototype._generateBoundary = function () {
|
|
345
361
|
// This generates a 50 character boundary similar to those used by Firefox.
|
|
346
|
-
// They are optimized for boyer-moore parsing.
|
|
347
|
-
var boundary = '--------------------------';
|
|
348
|
-
for (var i = 0; i < 24; i++) {
|
|
349
|
-
boundary += Math.floor(Math.random() * 10).toString(16);
|
|
350
|
-
}
|
|
351
362
|
|
|
352
|
-
|
|
363
|
+
// They are optimized for boyer-moore parsing.
|
|
364
|
+
this._boundary = '--------------------------' + crypto.randomBytes(12).toString('hex');
|
|
353
365
|
};
|
|
354
366
|
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
367
|
+
/*
|
|
368
|
+
* Note: getLengthSync DOESN'T calculate streams length
|
|
369
|
+
* As workaround one can calculate file size manually
|
|
370
|
+
* and add it as knownLength option
|
|
371
|
+
*/
|
|
372
|
+
FormData.prototype.getLengthSync = function () {
|
|
359
373
|
var knownLength = this._overheadLength + this._valueLength;
|
|
360
374
|
|
|
361
|
-
|
|
362
|
-
|
|
375
|
+
/*
|
|
376
|
+
* Don't get confused, there are 3 "internal" streams for each keyval pair
|
|
377
|
+
* so it basically checks if there is any value added to the form
|
|
378
|
+
*/
|
|
363
379
|
if (this._streams.length) {
|
|
364
380
|
knownLength += this._lastBoundary().length;
|
|
365
381
|
}
|
|
366
382
|
|
|
367
383
|
// https://github.com/form-data/form-data/issues/40
|
|
368
384
|
if (!this.hasKnownLength()) {
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
385
|
+
/*
|
|
386
|
+
* Some async length retrievers are present
|
|
387
|
+
* therefore synchronous length calculation is false.
|
|
388
|
+
* Please use getLength(callback) to get proper length
|
|
389
|
+
*/
|
|
372
390
|
this._error(new Error('Cannot calculate proper length in synchronous way.'));
|
|
373
391
|
}
|
|
374
392
|
|
|
375
393
|
return knownLength;
|
|
376
394
|
};
|
|
377
395
|
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
396
|
+
/*
|
|
397
|
+
* Public API to check if length of added values is known
|
|
398
|
+
* https://github.com/form-data/form-data/issues/196
|
|
399
|
+
* https://github.com/form-data/form-data/issues/262
|
|
400
|
+
*/
|
|
401
|
+
FormData.prototype.hasKnownLength = function () {
|
|
382
402
|
var hasKnownLength = true;
|
|
383
403
|
|
|
384
404
|
if (this._valuesToMeasure.length) {
|
|
@@ -388,7 +408,7 @@ FormData.prototype.hasKnownLength = function() {
|
|
|
388
408
|
return hasKnownLength;
|
|
389
409
|
};
|
|
390
410
|
|
|
391
|
-
FormData.prototype.getLength = function(cb) {
|
|
411
|
+
FormData.prototype.getLength = function (cb) {
|
|
392
412
|
var knownLength = this._overheadLength + this._valueLength;
|
|
393
413
|
|
|
394
414
|
if (this._streams.length) {
|
|
@@ -400,13 +420,13 @@ FormData.prototype.getLength = function(cb) {
|
|
|
400
420
|
return;
|
|
401
421
|
}
|
|
402
422
|
|
|
403
|
-
asynckit.parallel(this._valuesToMeasure, this._lengthRetriever, function(err, values) {
|
|
423
|
+
asynckit.parallel(this._valuesToMeasure, this._lengthRetriever, function (err, values) {
|
|
404
424
|
if (err) {
|
|
405
425
|
cb(err);
|
|
406
426
|
return;
|
|
407
427
|
}
|
|
408
428
|
|
|
409
|
-
values.forEach(function(length) {
|
|
429
|
+
values.forEach(function (length) {
|
|
410
430
|
knownLength += length;
|
|
411
431
|
});
|
|
412
432
|
|
|
@@ -414,22 +434,23 @@ FormData.prototype.getLength = function(cb) {
|
|
|
414
434
|
});
|
|
415
435
|
};
|
|
416
436
|
|
|
417
|
-
FormData.prototype.submit = function(params, cb) {
|
|
418
|
-
var request
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
;
|
|
437
|
+
FormData.prototype.submit = function (params, cb) {
|
|
438
|
+
var request;
|
|
439
|
+
var options;
|
|
440
|
+
var defaults = { method: 'post' };
|
|
422
441
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
442
|
+
/*
|
|
443
|
+
* parse provided url if it's string
|
|
444
|
+
* or treat it as options object
|
|
445
|
+
*/
|
|
446
|
+
if (typeof params === 'string') {
|
|
426
447
|
|
|
427
448
|
params = parseUrl(params);
|
|
428
449
|
options = populate({
|
|
429
450
|
port: params.port,
|
|
430
451
|
path: params.pathname,
|
|
431
452
|
host: params.hostname,
|
|
432
|
-
protocol: params.protocol
|
|
453
|
+
protocol: params.protocol,
|
|
433
454
|
}, defaults);
|
|
434
455
|
|
|
435
456
|
// use custom params
|
|
@@ -438,7 +459,7 @@ FormData.prototype.submit = function(params, cb) {
|
|
|
438
459
|
options = populate(params, defaults);
|
|
439
460
|
// if no port provided use default one
|
|
440
461
|
if (!options.port) {
|
|
441
|
-
options.port = options.protocol
|
|
462
|
+
options.port = options.protocol === 'https:' ? 443 : 80;
|
|
442
463
|
}
|
|
443
464
|
}
|
|
444
465
|
|
|
@@ -446,14 +467,14 @@ FormData.prototype.submit = function(params, cb) {
|
|
|
446
467
|
options.headers = this.getHeaders(params.headers);
|
|
447
468
|
|
|
448
469
|
// https if specified, fallback to http in any other case
|
|
449
|
-
if (options.protocol
|
|
470
|
+
if (options.protocol === 'https:') {
|
|
450
471
|
request = https.request(options);
|
|
451
472
|
} else {
|
|
452
473
|
request = http.request(options);
|
|
453
474
|
}
|
|
454
475
|
|
|
455
476
|
// get content length and fire away
|
|
456
|
-
this.getLength(function(err, length) {
|
|
477
|
+
this.getLength(function (err, length) {
|
|
457
478
|
if (err) {
|
|
458
479
|
this._error(err);
|
|
459
480
|
return;
|
|
@@ -472,7 +493,7 @@ FormData.prototype.submit = function(params, cb) {
|
|
|
472
493
|
return request;
|
|
473
494
|
};
|
|
474
495
|
|
|
475
|
-
FormData.prototype._error = function(err) {
|
|
496
|
+
FormData.prototype._error = function (err) {
|
|
476
497
|
if (!this.error) {
|
|
477
498
|
this.error = err;
|
|
478
499
|
this.pause();
|
|
@@ -484,3 +505,5 @@ FormData.prototype.toString = function () {
|
|
|
484
505
|
return '[object FormData]';
|
|
485
506
|
};
|
|
486
507
|
setToStringTag(FormData, 'FormData');
|
|
508
|
+
|
|
509
|
+
module.exports = FormData;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
|
|
2
|
-
module.exports = function(dst, src) {
|
|
1
|
+
'use strict';
|
|
3
2
|
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
// populates missing values
|
|
4
|
+
module.exports = function (dst, src) {
|
|
5
|
+
Object.keys(src).forEach(function (prop) {
|
|
6
6
|
dst[prop] = dst[prop] || src[prop];
|
|
7
7
|
});
|
|
8
8
|
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"author": "Felix Geisendörfer <felix@debuggable.com> (http://debuggable.com/)",
|
|
3
3
|
"name": "form-data",
|
|
4
4
|
"description": "A library to create readable \"multipart/form-data\" streams. Can be used to submit forms and file uploads to other web applications.",
|
|
5
|
-
"version": "2.5.
|
|
5
|
+
"version": "2.5.4",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "git://github.com/form-data/form-data.git"
|
|
@@ -19,7 +19,6 @@
|
|
|
19
19
|
"posttest": "npx npm@'>=10.2' audit --production",
|
|
20
20
|
"lint": "eslint --ext=js,mjs .",
|
|
21
21
|
"report": "istanbul report lcov text",
|
|
22
|
-
"ci-lint": "is-node-modern 8 && npm run lint || is-node-not-modern 8",
|
|
23
22
|
"ci-test": "npm run tests-only && npm run browser && npm run report",
|
|
24
23
|
"predebug": "rimraf coverage test/tmp",
|
|
25
24
|
"debug": "verbose=1 ./test/run.js",
|
|
@@ -29,14 +28,12 @@
|
|
|
29
28
|
"get-version": "node -e \"console.log(require('./package.json').version)\"",
|
|
30
29
|
"update-readme": "sed -i.bak 's/\\/master\\.svg/\\/v'$(npm --silent run get-version)'.svg/g' README.md",
|
|
31
30
|
"restore-readme": "mv README.md.bak README.md",
|
|
32
|
-
"prepublish": "in-publish
|
|
33
|
-
"
|
|
31
|
+
"prepublish": "not-in-publish || npm run prepublishOnly",
|
|
32
|
+
"prepublishOnly": "npm run update-readme",
|
|
33
|
+
"postpublish": "npm run restore-readme",
|
|
34
|
+
"version": "auto-changelog && git add CHANGELOG.md",
|
|
35
|
+
"postversion": "auto-changelog && git add CHANGELOG.md && git commit --no-edit --amend && git tag -f \"v$(node -e \"console.log(require('./package.json').version)\")\""
|
|
34
36
|
},
|
|
35
|
-
"pre-commit": [
|
|
36
|
-
"lint",
|
|
37
|
-
"ci-test",
|
|
38
|
-
"check"
|
|
39
|
-
],
|
|
40
37
|
"engines": {
|
|
41
38
|
"node": ">= 0.12"
|
|
42
39
|
},
|
|
@@ -44,32 +41,42 @@
|
|
|
44
41
|
"asynckit": "^0.4.0",
|
|
45
42
|
"combined-stream": "^1.0.8",
|
|
46
43
|
"es-set-tostringtag": "^2.1.0",
|
|
44
|
+
"has-own": "^1.0.1",
|
|
47
45
|
"mime-types": "^2.1.35",
|
|
48
46
|
"safe-buffer": "^5.2.1"
|
|
49
47
|
},
|
|
50
48
|
"devDependencies": {
|
|
51
|
-
"@
|
|
52
|
-
"
|
|
53
|
-
"@types/node": "^12.20.55",
|
|
49
|
+
"@ljharb/eslint-config": "^21.2.0",
|
|
50
|
+
"auto-changelog": "^2.5.0",
|
|
54
51
|
"browserify": "^13.3.0",
|
|
55
52
|
"browserify-istanbul": "^2.0.0",
|
|
56
53
|
"coveralls": "^3.1.1",
|
|
57
54
|
"cross-spawn": "^4.0.2",
|
|
58
|
-
"
|
|
55
|
+
"encoding": "^0.1.13",
|
|
56
|
+
"eslint": "=8.8.0",
|
|
59
57
|
"fake": "^0.2.2",
|
|
60
58
|
"far": "^0.0.7",
|
|
61
59
|
"formidable": "^1.2.6",
|
|
62
60
|
"in-publish": "^2.0.1",
|
|
63
|
-
"is-node-modern": "^1.0.0",
|
|
64
61
|
"istanbul": "^0.4.5",
|
|
62
|
+
"js-randomness-predictor": "^1.5.5",
|
|
65
63
|
"obake": "^0.1.2",
|
|
66
64
|
"phantomjs-prebuilt": "^2.1.16",
|
|
67
65
|
"pkgfiles": "^2.3.2",
|
|
68
66
|
"pre-commit": "^1.2.2",
|
|
67
|
+
"puppeteer": "^1.20.0",
|
|
69
68
|
"request": "~2.87.0",
|
|
70
69
|
"rimraf": "^2.7.1",
|
|
71
|
-
"
|
|
72
|
-
"
|
|
70
|
+
"semver": "^6.3.1",
|
|
71
|
+
"tape": "^5.9.0"
|
|
73
72
|
},
|
|
74
|
-
"license": "MIT"
|
|
73
|
+
"license": "MIT",
|
|
74
|
+
"auto-changelog": {
|
|
75
|
+
"output": "CHANGELOG.md",
|
|
76
|
+
"template": "keepachangelog",
|
|
77
|
+
"unreleased": false,
|
|
78
|
+
"commitLimit": false,
|
|
79
|
+
"backfillLimit": false,
|
|
80
|
+
"hideCredit": true
|
|
81
|
+
}
|
|
75
82
|
}
|