mirror of
https://github.com/hashicorp/setup-terraform.git
synced 2025-12-16 16:42:35 +00:00
Bump form-data from 4.0.2 to 4.0.4 (#496)
* Bump form-data from 4.0.2 to 4.0.4 Bumps [form-data](https://github.com/form-data/form-data) from 4.0.2 to 4.0.4. - [Release notes](https://github.com/form-data/form-data/releases) - [Changelog](https://github.com/form-data/form-data/blob/master/CHANGELOG.md) - [Commits](https://github.com/form-data/form-data/compare/v4.0.2...v4.0.4) --- updated-dependencies: - dependency-name: form-data dependency-version: 4.0.4 dependency-type: indirect ... Signed-off-by: dependabot[bot] <support@github.com> * run build --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Ansgar Mertens <ansgar@hashicorp.com>
This commit is contained in:
parent
1428cf0603
commit
c0a118784f
2 changed files with 141 additions and 147 deletions
273
dist/index.js
vendored
273
dist/index.js
vendored
|
|
@ -16285,6 +16285,9 @@ module.exports.wrap = wrap;
|
||||||
/***/ 6454:
|
/***/ 6454:
|
||||||
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
/***/ ((module, __unused_webpack_exports, __nccwpck_require__) => {
|
||||||
|
|
||||||
|
"use strict";
|
||||||
|
|
||||||
|
|
||||||
var CombinedStream = __nccwpck_require__(5630);
|
var CombinedStream = __nccwpck_require__(5630);
|
||||||
var util = __nccwpck_require__(9023);
|
var util = __nccwpck_require__(9023);
|
||||||
var path = __nccwpck_require__(6928);
|
var path = __nccwpck_require__(6928);
|
||||||
|
|
@ -16293,24 +16296,20 @@ var https = __nccwpck_require__(5692);
|
||||||
var parseUrl = (__nccwpck_require__(7016).parse);
|
var parseUrl = (__nccwpck_require__(7016).parse);
|
||||||
var fs = __nccwpck_require__(9896);
|
var fs = __nccwpck_require__(9896);
|
||||||
var Stream = (__nccwpck_require__(2203).Stream);
|
var Stream = (__nccwpck_require__(2203).Stream);
|
||||||
|
var crypto = __nccwpck_require__(6982);
|
||||||
var mime = __nccwpck_require__(4096);
|
var mime = __nccwpck_require__(4096);
|
||||||
var asynckit = __nccwpck_require__(1324);
|
var asynckit = __nccwpck_require__(1324);
|
||||||
var setToStringTag = __nccwpck_require__(8700);
|
var setToStringTag = __nccwpck_require__(8700);
|
||||||
|
var hasOwn = __nccwpck_require__(4076);
|
||||||
var populate = __nccwpck_require__(1835);
|
var populate = __nccwpck_require__(1835);
|
||||||
|
|
||||||
// Public API
|
|
||||||
module.exports = FormData;
|
|
||||||
|
|
||||||
// make it a Stream
|
|
||||||
util.inherits(FormData, CombinedStream);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create readable "multipart/form-data" streams.
|
* Create readable "multipart/form-data" streams.
|
||||||
* Can be used to submit forms
|
* Can be used to submit forms
|
||||||
* and file uploads to other web applications.
|
* and file uploads to other web applications.
|
||||||
*
|
*
|
||||||
* @constructor
|
* @constructor
|
||||||
* @param {Object} options - Properties to be added/overriden for FormData and CombinedStream
|
* @param {object} options - Properties to be added/overriden for FormData and CombinedStream
|
||||||
*/
|
*/
|
||||||
function FormData(options) {
|
function FormData(options) {
|
||||||
if (!(this instanceof FormData)) {
|
if (!(this instanceof FormData)) {
|
||||||
|
|
@ -16323,35 +16322,39 @@ function FormData(options) {
|
||||||
|
|
||||||
CombinedStream.call(this);
|
CombinedStream.call(this);
|
||||||
|
|
||||||
options = options || {};
|
options = options || {}; // eslint-disable-line no-param-reassign
|
||||||
for (var option in options) {
|
for (var option in options) { // eslint-disable-line no-restricted-syntax
|
||||||
this[option] = options[option];
|
this[option] = options[option];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// make it a Stream
|
||||||
|
util.inherits(FormData, CombinedStream);
|
||||||
|
|
||||||
FormData.LINE_BREAK = '\r\n';
|
FormData.LINE_BREAK = '\r\n';
|
||||||
FormData.DEFAULT_CONTENT_TYPE = 'application/octet-stream';
|
FormData.DEFAULT_CONTENT_TYPE = 'application/octet-stream';
|
||||||
|
|
||||||
FormData.prototype.append = function(field, value, options) {
|
FormData.prototype.append = function (field, value, options) {
|
||||||
|
options = options || {}; // eslint-disable-line no-param-reassign
|
||||||
options = options || {};
|
|
||||||
|
|
||||||
// allow filename as single option
|
// allow filename as single option
|
||||||
if (typeof options == 'string') {
|
if (typeof options === 'string') {
|
||||||
options = {filename: options};
|
options = { filename: options }; // eslint-disable-line no-param-reassign
|
||||||
}
|
}
|
||||||
|
|
||||||
var append = CombinedStream.prototype.append.bind(this);
|
var append = CombinedStream.prototype.append.bind(this);
|
||||||
|
|
||||||
// all that streamy business can't handle numbers
|
// all that streamy business can't handle numbers
|
||||||
if (typeof value == 'number') {
|
if (typeof value === 'number' || value == null) {
|
||||||
value = '' + value;
|
value = String(value); // eslint-disable-line no-param-reassign
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/felixge/node-form-data/issues/38
|
// https://github.com/felixge/node-form-data/issues/38
|
||||||
if (Array.isArray(value)) {
|
if (Array.isArray(value)) {
|
||||||
// Please convert your array into string
|
/*
|
||||||
// the way web server expects it
|
* Please convert your array into string
|
||||||
|
* the way web server expects it
|
||||||
|
*/
|
||||||
this._error(new Error('Arrays are not supported.'));
|
this._error(new Error('Arrays are not supported.'));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
@ -16367,15 +16370,17 @@ FormData.prototype.append = function(field, value, options) {
|
||||||
this._trackLength(header, value, options);
|
this._trackLength(header, value, options);
|
||||||
};
|
};
|
||||||
|
|
||||||
FormData.prototype._trackLength = function(header, value, options) {
|
FormData.prototype._trackLength = function (header, value, options) {
|
||||||
var valueLength = 0;
|
var valueLength = 0;
|
||||||
|
|
||||||
// used w/ getLengthSync(), when length is known.
|
/*
|
||||||
// e.g. for streaming directly from a remote server,
|
* used w/ getLengthSync(), when length is known.
|
||||||
// w/ a known file a size, and not wanting to wait for
|
* e.g. for streaming directly from a remote server,
|
||||||
// incoming file to finish to get its size.
|
* w/ a known file a size, and not wanting to wait for
|
||||||
|
* incoming file to finish to get its size.
|
||||||
|
*/
|
||||||
if (options.knownLength != null) {
|
if (options.knownLength != null) {
|
||||||
valueLength += +options.knownLength;
|
valueLength += Number(options.knownLength);
|
||||||
} else if (Buffer.isBuffer(value)) {
|
} else if (Buffer.isBuffer(value)) {
|
||||||
valueLength = value.length;
|
valueLength = value.length;
|
||||||
} else if (typeof value === 'string') {
|
} else if (typeof value === 'string') {
|
||||||
|
|
@ -16385,12 +16390,10 @@ FormData.prototype._trackLength = function(header, value, options) {
|
||||||
this._valueLength += valueLength;
|
this._valueLength += valueLength;
|
||||||
|
|
||||||
// @check why add CRLF? does this account for custom/multiple CRLFs?
|
// @check why add CRLF? does this account for custom/multiple CRLFs?
|
||||||
this._overheadLength +=
|
this._overheadLength += Buffer.byteLength(header) + FormData.LINE_BREAK.length;
|
||||||
Buffer.byteLength(header) +
|
|
||||||
FormData.LINE_BREAK.length;
|
|
||||||
|
|
||||||
// empty or either doesn't have path or not an http response or not a stream
|
// empty or either doesn't have path or not an http response or not a stream
|
||||||
if (!value || ( !value.path && !(value.readable && Object.prototype.hasOwnProperty.call(value, 'httpVersion')) && !(value instanceof Stream))) {
|
if (!value || (!value.path && !(value.readable && hasOwn(value, 'httpVersion')) && !(value instanceof Stream))) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -16400,9 +16403,8 @@ FormData.prototype._trackLength = function(header, value, options) {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
FormData.prototype._lengthRetriever = function(value, callback) {
|
FormData.prototype._lengthRetriever = function (value, callback) {
|
||||||
if (Object.prototype.hasOwnProperty.call(value, 'fd')) {
|
if (hasOwn(value, 'fd')) {
|
||||||
|
|
||||||
// take read range into a account
|
// take read range into a account
|
||||||
// `end` = Infinity –> read file till the end
|
// `end` = Infinity –> read file till the end
|
||||||
//
|
//
|
||||||
|
|
@ -16411,54 +16413,52 @@ FormData.prototype._lengthRetriever = function(value, callback) {
|
||||||
// Fix it when node fixes it.
|
// Fix it when node fixes it.
|
||||||
// https://github.com/joyent/node/issues/7819
|
// https://github.com/joyent/node/issues/7819
|
||||||
if (value.end != undefined && value.end != Infinity && value.start != undefined) {
|
if (value.end != undefined && value.end != Infinity && value.start != undefined) {
|
||||||
|
|
||||||
// when end specified
|
// when end specified
|
||||||
// no need to calculate range
|
// no need to calculate range
|
||||||
// inclusive, starts with 0
|
// inclusive, starts with 0
|
||||||
callback(null, value.end + 1 - (value.start ? value.start : 0));
|
callback(null, value.end + 1 - (value.start ? value.start : 0)); // eslint-disable-line callback-return
|
||||||
|
|
||||||
// not that fast snoopy
|
// not that fast snoopy
|
||||||
} else {
|
} else {
|
||||||
// still need to fetch file size from fs
|
// still need to fetch file size from fs
|
||||||
fs.stat(value.path, function(err, stat) {
|
fs.stat(value.path, function (err, stat) {
|
||||||
|
|
||||||
var fileSize;
|
|
||||||
|
|
||||||
if (err) {
|
if (err) {
|
||||||
callback(err);
|
callback(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// update final size based on the range options
|
// update final size based on the range options
|
||||||
fileSize = stat.size - (value.start ? value.start : 0);
|
var fileSize = stat.size - (value.start ? value.start : 0);
|
||||||
callback(null, fileSize);
|
callback(null, fileSize);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// or http response
|
// or http response
|
||||||
} else if (Object.prototype.hasOwnProperty.call(value, 'httpVersion')) {
|
} else if (hasOwn(value, 'httpVersion')) {
|
||||||
callback(null, +value.headers['content-length']);
|
callback(null, Number(value.headers['content-length'])); // eslint-disable-line callback-return
|
||||||
|
|
||||||
// or request stream http://github.com/mikeal/request
|
// or request stream http://github.com/mikeal/request
|
||||||
} else if (Object.prototype.hasOwnProperty.call(value, 'httpModule')) {
|
} else if (hasOwn(value, 'httpModule')) {
|
||||||
// wait till response come back
|
// wait till response come back
|
||||||
value.on('response', function(response) {
|
value.on('response', function (response) {
|
||||||
value.pause();
|
value.pause();
|
||||||
callback(null, +response.headers['content-length']);
|
callback(null, Number(response.headers['content-length']));
|
||||||
});
|
});
|
||||||
value.resume();
|
value.resume();
|
||||||
|
|
||||||
// something else
|
// something else
|
||||||
} else {
|
} else {
|
||||||
callback('Unknown stream');
|
callback('Unknown stream'); // eslint-disable-line callback-return
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
FormData.prototype._multiPartHeader = function(field, value, options) {
|
FormData.prototype._multiPartHeader = function (field, value, options) {
|
||||||
// custom header specified (as string)?
|
/*
|
||||||
// it becomes responsible for boundary
|
* custom header specified (as string)?
|
||||||
// (e.g. to handle extra CRLFs on .NET servers)
|
* it becomes responsible for boundary
|
||||||
if (typeof options.header == 'string') {
|
* (e.g. to handle extra CRLFs on .NET servers)
|
||||||
|
*/
|
||||||
|
if (typeof options.header === 'string') {
|
||||||
return options.header;
|
return options.header;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -16466,7 +16466,7 @@ FormData.prototype._multiPartHeader = function(field, value, options) {
|
||||||
var contentType = this._getContentType(value, options);
|
var contentType = this._getContentType(value, options);
|
||||||
|
|
||||||
var contents = '';
|
var contents = '';
|
||||||
var headers = {
|
var headers = {
|
||||||
// add custom disposition as third element or keep it two elements if not
|
// add custom disposition as third element or keep it two elements if not
|
||||||
'Content-Disposition': ['form-data', 'name="' + field + '"'].concat(contentDisposition || []),
|
'Content-Disposition': ['form-data', 'name="' + field + '"'].concat(contentDisposition || []),
|
||||||
// if no content type. allow it to be empty array
|
// if no content type. allow it to be empty array
|
||||||
|
|
@ -16474,18 +16474,18 @@ FormData.prototype._multiPartHeader = function(field, value, options) {
|
||||||
};
|
};
|
||||||
|
|
||||||
// allow custom headers.
|
// allow custom headers.
|
||||||
if (typeof options.header == 'object') {
|
if (typeof options.header === 'object') {
|
||||||
populate(headers, options.header);
|
populate(headers, options.header);
|
||||||
}
|
}
|
||||||
|
|
||||||
var header;
|
var header;
|
||||||
for (var prop in headers) {
|
for (var prop in headers) { // eslint-disable-line no-restricted-syntax
|
||||||
if (Object.prototype.hasOwnProperty.call(headers, prop)) {
|
if (hasOwn(headers, prop)) {
|
||||||
header = headers[prop];
|
header = headers[prop];
|
||||||
|
|
||||||
// skip nullish headers.
|
// skip nullish headers.
|
||||||
if (header == null) {
|
if (header == null) {
|
||||||
continue;
|
continue; // eslint-disable-line no-restricted-syntax, no-continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// convert all headers to arrays.
|
// convert all headers to arrays.
|
||||||
|
|
@ -16503,49 +16503,45 @@ FormData.prototype._multiPartHeader = function(field, value, options) {
|
||||||
return '--' + this.getBoundary() + FormData.LINE_BREAK + contents + FormData.LINE_BREAK;
|
return '--' + this.getBoundary() + FormData.LINE_BREAK + contents + FormData.LINE_BREAK;
|
||||||
};
|
};
|
||||||
|
|
||||||
FormData.prototype._getContentDisposition = function(value, options) {
|
FormData.prototype._getContentDisposition = function (value, options) { // eslint-disable-line consistent-return
|
||||||
|
var filename;
|
||||||
var filename
|
|
||||||
, contentDisposition
|
|
||||||
;
|
|
||||||
|
|
||||||
if (typeof options.filepath === 'string') {
|
if (typeof options.filepath === 'string') {
|
||||||
// custom filepath for relative paths
|
// custom filepath for relative paths
|
||||||
filename = path.normalize(options.filepath).replace(/\\/g, '/');
|
filename = path.normalize(options.filepath).replace(/\\/g, '/');
|
||||||
} else if (options.filename || value.name || value.path) {
|
} else if (options.filename || (value && (value.name || value.path))) {
|
||||||
// custom filename take precedence
|
/*
|
||||||
// formidable and the browser add a name property
|
* custom filename take precedence
|
||||||
// fs- and request- streams have path property
|
* formidable and the browser add a name property
|
||||||
filename = path.basename(options.filename || value.name || value.path);
|
* fs- and request- streams have path property
|
||||||
} else if (value.readable && Object.prototype.hasOwnProperty.call(value, 'httpVersion')) {
|
*/
|
||||||
|
filename = path.basename(options.filename || (value && (value.name || value.path)));
|
||||||
|
} else if (value && value.readable && hasOwn(value, 'httpVersion')) {
|
||||||
// or try http response
|
// or try http response
|
||||||
filename = path.basename(value.client._httpMessage.path || '');
|
filename = path.basename(value.client._httpMessage.path || '');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (filename) {
|
if (filename) {
|
||||||
contentDisposition = 'filename="' + filename + '"';
|
return 'filename="' + filename + '"';
|
||||||
}
|
}
|
||||||
|
|
||||||
return contentDisposition;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
FormData.prototype._getContentType = function(value, options) {
|
FormData.prototype._getContentType = function (value, options) {
|
||||||
|
|
||||||
// use custom content-type above all
|
// use custom content-type above all
|
||||||
var contentType = options.contentType;
|
var contentType = options.contentType;
|
||||||
|
|
||||||
// or try `name` from formidable, browser
|
// or try `name` from formidable, browser
|
||||||
if (!contentType && value.name) {
|
if (!contentType && value && value.name) {
|
||||||
contentType = mime.lookup(value.name);
|
contentType = mime.lookup(value.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
// or try `path` from fs-, request- streams
|
// or try `path` from fs-, request- streams
|
||||||
if (!contentType && value.path) {
|
if (!contentType && value && value.path) {
|
||||||
contentType = mime.lookup(value.path);
|
contentType = mime.lookup(value.path);
|
||||||
}
|
}
|
||||||
|
|
||||||
// or if it's http-reponse
|
// or if it's http-reponse
|
||||||
if (!contentType && value.readable && Object.prototype.hasOwnProperty.call(value, 'httpVersion')) {
|
if (!contentType && value && value.readable && hasOwn(value, 'httpVersion')) {
|
||||||
contentType = value.headers['content-type'];
|
contentType = value.headers['content-type'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -16555,18 +16551,18 @@ FormData.prototype._getContentType = function(value, options) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// fallback to the default content type if `value` is not simple value
|
// fallback to the default content type if `value` is not simple value
|
||||||
if (!contentType && typeof value == 'object') {
|
if (!contentType && value && typeof value === 'object') {
|
||||||
contentType = FormData.DEFAULT_CONTENT_TYPE;
|
contentType = FormData.DEFAULT_CONTENT_TYPE;
|
||||||
}
|
}
|
||||||
|
|
||||||
return contentType;
|
return contentType;
|
||||||
};
|
};
|
||||||
|
|
||||||
FormData.prototype._multiPartFooter = function() {
|
FormData.prototype._multiPartFooter = function () {
|
||||||
return function(next) {
|
return function (next) {
|
||||||
var footer = FormData.LINE_BREAK;
|
var footer = FormData.LINE_BREAK;
|
||||||
|
|
||||||
var lastPart = (this._streams.length === 0);
|
var lastPart = this._streams.length === 0;
|
||||||
if (lastPart) {
|
if (lastPart) {
|
||||||
footer += this._lastBoundary();
|
footer += this._lastBoundary();
|
||||||
}
|
}
|
||||||
|
|
@ -16575,18 +16571,18 @@ FormData.prototype._multiPartFooter = function() {
|
||||||
}.bind(this);
|
}.bind(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
FormData.prototype._lastBoundary = function() {
|
FormData.prototype._lastBoundary = function () {
|
||||||
return '--' + this.getBoundary() + '--' + FormData.LINE_BREAK;
|
return '--' + this.getBoundary() + '--' + FormData.LINE_BREAK;
|
||||||
};
|
};
|
||||||
|
|
||||||
FormData.prototype.getHeaders = function(userHeaders) {
|
FormData.prototype.getHeaders = function (userHeaders) {
|
||||||
var header;
|
var header;
|
||||||
var formHeaders = {
|
var formHeaders = {
|
||||||
'content-type': 'multipart/form-data; boundary=' + this.getBoundary()
|
'content-type': 'multipart/form-data; boundary=' + this.getBoundary()
|
||||||
};
|
};
|
||||||
|
|
||||||
for (header in userHeaders) {
|
for (header in userHeaders) { // eslint-disable-line no-restricted-syntax
|
||||||
if (Object.prototype.hasOwnProperty.call(userHeaders, header)) {
|
if (hasOwn(userHeaders, header)) {
|
||||||
formHeaders[header.toLowerCase()] = userHeaders[header];
|
formHeaders[header.toLowerCase()] = userHeaders[header];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -16594,11 +16590,14 @@ FormData.prototype.getHeaders = function(userHeaders) {
|
||||||
return formHeaders;
|
return formHeaders;
|
||||||
};
|
};
|
||||||
|
|
||||||
FormData.prototype.setBoundary = function(boundary) {
|
FormData.prototype.setBoundary = function (boundary) {
|
||||||
|
if (typeof boundary !== 'string') {
|
||||||
|
throw new TypeError('FormData boundary must be a string');
|
||||||
|
}
|
||||||
this._boundary = boundary;
|
this._boundary = boundary;
|
||||||
};
|
};
|
||||||
|
|
||||||
FormData.prototype.getBoundary = function() {
|
FormData.prototype.getBoundary = function () {
|
||||||
if (!this._boundary) {
|
if (!this._boundary) {
|
||||||
this._generateBoundary();
|
this._generateBoundary();
|
||||||
}
|
}
|
||||||
|
|
@ -16606,60 +16605,55 @@ FormData.prototype.getBoundary = function() {
|
||||||
return this._boundary;
|
return this._boundary;
|
||||||
};
|
};
|
||||||
|
|
||||||
FormData.prototype.getBuffer = function() {
|
FormData.prototype.getBuffer = function () {
|
||||||
var dataBuffer = new Buffer.alloc(0);
|
var dataBuffer = new Buffer.alloc(0); // eslint-disable-line new-cap
|
||||||
var boundary = this.getBoundary();
|
var boundary = this.getBoundary();
|
||||||
|
|
||||||
// Create the form content. Add Line breaks to the end of data.
|
// Create the form content. Add Line breaks to the end of data.
|
||||||
for (var i = 0, len = this._streams.length; i < len; i++) {
|
for (var i = 0, len = this._streams.length; i < len; i++) {
|
||||||
if (typeof this._streams[i] !== 'function') {
|
if (typeof this._streams[i] !== 'function') {
|
||||||
|
|
||||||
// Add content to the buffer.
|
// Add content to the buffer.
|
||||||
if(Buffer.isBuffer(this._streams[i])) {
|
if (Buffer.isBuffer(this._streams[i])) {
|
||||||
dataBuffer = Buffer.concat( [dataBuffer, this._streams[i]]);
|
dataBuffer = Buffer.concat([dataBuffer, this._streams[i]]);
|
||||||
}else {
|
} else {
|
||||||
dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(this._streams[i])]);
|
dataBuffer = Buffer.concat([dataBuffer, Buffer.from(this._streams[i])]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add break after content.
|
// Add break after content.
|
||||||
if (typeof this._streams[i] !== 'string' || this._streams[i].substring( 2, boundary.length + 2 ) !== boundary) {
|
if (typeof this._streams[i] !== 'string' || this._streams[i].substring(2, boundary.length + 2) !== boundary) {
|
||||||
dataBuffer = Buffer.concat( [dataBuffer, Buffer.from(FormData.LINE_BREAK)] );
|
dataBuffer = Buffer.concat([dataBuffer, Buffer.from(FormData.LINE_BREAK)]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add the footer and return the Buffer object.
|
// Add the footer and return the Buffer object.
|
||||||
return Buffer.concat( [dataBuffer, Buffer.from(this._lastBoundary())] );
|
return Buffer.concat([dataBuffer, Buffer.from(this._lastBoundary())]);
|
||||||
};
|
};
|
||||||
|
|
||||||
FormData.prototype._generateBoundary = function() {
|
FormData.prototype._generateBoundary = function () {
|
||||||
// This generates a 50 character boundary similar to those used by Firefox.
|
// This generates a 50 character boundary similar to those used by Firefox.
|
||||||
// They are optimized for boyer-moore parsing.
|
|
||||||
var boundary = '--------------------------';
|
|
||||||
for (var i = 0; i < 24; i++) {
|
|
||||||
boundary += Math.floor(Math.random() * 10).toString(16);
|
|
||||||
}
|
|
||||||
|
|
||||||
this._boundary = boundary;
|
// They are optimized for boyer-moore parsing.
|
||||||
|
this._boundary = '--------------------------' + crypto.randomBytes(12).toString('hex');
|
||||||
};
|
};
|
||||||
|
|
||||||
// Note: getLengthSync DOESN'T calculate streams length
|
// Note: getLengthSync DOESN'T calculate streams length
|
||||||
// As workaround one can calculate file size manually
|
// As workaround one can calculate file size manually and add it as knownLength option
|
||||||
// and add it as knownLength option
|
FormData.prototype.getLengthSync = function () {
|
||||||
FormData.prototype.getLengthSync = function() {
|
|
||||||
var knownLength = this._overheadLength + this._valueLength;
|
var knownLength = this._overheadLength + this._valueLength;
|
||||||
|
|
||||||
// Don't get confused, there are 3 "internal" streams for each keyval pair
|
// Don't get confused, there are 3 "internal" streams for each keyval pair so it basically checks if there is any value added to the form
|
||||||
// so it basically checks if there is any value added to the form
|
|
||||||
if (this._streams.length) {
|
if (this._streams.length) {
|
||||||
knownLength += this._lastBoundary().length;
|
knownLength += this._lastBoundary().length;
|
||||||
}
|
}
|
||||||
|
|
||||||
// https://github.com/form-data/form-data/issues/40
|
// https://github.com/form-data/form-data/issues/40
|
||||||
if (!this.hasKnownLength()) {
|
if (!this.hasKnownLength()) {
|
||||||
// Some async length retrievers are present
|
/*
|
||||||
// therefore synchronous length calculation is false.
|
* Some async length retrievers are present
|
||||||
// Please use getLength(callback) to get proper length
|
* therefore synchronous length calculation is false.
|
||||||
|
* Please use getLength(callback) to get proper length
|
||||||
|
*/
|
||||||
this._error(new Error('Cannot calculate proper length in synchronous way.'));
|
this._error(new Error('Cannot calculate proper length in synchronous way.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -16669,7 +16663,7 @@ FormData.prototype.getLengthSync = function() {
|
||||||
// Public API to check if length of added values is known
|
// Public API to check if length of added values is known
|
||||||
// https://github.com/form-data/form-data/issues/196
|
// https://github.com/form-data/form-data/issues/196
|
||||||
// https://github.com/form-data/form-data/issues/262
|
// https://github.com/form-data/form-data/issues/262
|
||||||
FormData.prototype.hasKnownLength = function() {
|
FormData.prototype.hasKnownLength = function () {
|
||||||
var hasKnownLength = true;
|
var hasKnownLength = true;
|
||||||
|
|
||||||
if (this._valuesToMeasure.length) {
|
if (this._valuesToMeasure.length) {
|
||||||
|
|
@ -16679,7 +16673,7 @@ FormData.prototype.hasKnownLength = function() {
|
||||||
return hasKnownLength;
|
return hasKnownLength;
|
||||||
};
|
};
|
||||||
|
|
||||||
FormData.prototype.getLength = function(cb) {
|
FormData.prototype.getLength = function (cb) {
|
||||||
var knownLength = this._overheadLength + this._valueLength;
|
var knownLength = this._overheadLength + this._valueLength;
|
||||||
|
|
||||||
if (this._streams.length) {
|
if (this._streams.length) {
|
||||||
|
|
@ -16691,13 +16685,13 @@ FormData.prototype.getLength = function(cb) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
asynckit.parallel(this._valuesToMeasure, this._lengthRetriever, function(err, values) {
|
asynckit.parallel(this._valuesToMeasure, this._lengthRetriever, function (err, values) {
|
||||||
if (err) {
|
if (err) {
|
||||||
cb(err);
|
cb(err);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
values.forEach(function(length) {
|
values.forEach(function (length) {
|
||||||
knownLength += length;
|
knownLength += length;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -16705,31 +16699,26 @@ FormData.prototype.getLength = function(cb) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
FormData.prototype.submit = function(params, cb) {
|
FormData.prototype.submit = function (params, cb) {
|
||||||
var request
|
var request;
|
||||||
, options
|
var options;
|
||||||
, defaults = {method: 'post'}
|
var defaults = { method: 'post' };
|
||||||
;
|
|
||||||
|
|
||||||
// parse provided url if it's string
|
// parse provided url if it's string or treat it as options object
|
||||||
// or treat it as options object
|
if (typeof params === 'string') {
|
||||||
if (typeof params == 'string') {
|
params = parseUrl(params); // eslint-disable-line no-param-reassign
|
||||||
|
/* eslint sort-keys: 0 */
|
||||||
params = parseUrl(params);
|
|
||||||
options = populate({
|
options = populate({
|
||||||
port: params.port,
|
port: params.port,
|
||||||
path: params.pathname,
|
path: params.pathname,
|
||||||
host: params.hostname,
|
host: params.hostname,
|
||||||
protocol: params.protocol
|
protocol: params.protocol
|
||||||
}, defaults);
|
}, defaults);
|
||||||
|
} else { // use custom params
|
||||||
// use custom params
|
|
||||||
} else {
|
|
||||||
|
|
||||||
options = populate(params, defaults);
|
options = populate(params, defaults);
|
||||||
// if no port provided use default one
|
// if no port provided use default one
|
||||||
if (!options.port) {
|
if (!options.port) {
|
||||||
options.port = options.protocol == 'https:' ? 443 : 80;
|
options.port = options.protocol === 'https:' ? 443 : 80;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -16737,14 +16726,14 @@ FormData.prototype.submit = function(params, cb) {
|
||||||
options.headers = this.getHeaders(params.headers);
|
options.headers = this.getHeaders(params.headers);
|
||||||
|
|
||||||
// https if specified, fallback to http in any other case
|
// https if specified, fallback to http in any other case
|
||||||
if (options.protocol == 'https:') {
|
if (options.protocol === 'https:') {
|
||||||
request = https.request(options);
|
request = https.request(options);
|
||||||
} else {
|
} else {
|
||||||
request = http.request(options);
|
request = http.request(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
// get content length and fire away
|
// get content length and fire away
|
||||||
this.getLength(function(err, length) {
|
this.getLength(function (err, length) {
|
||||||
if (err && err !== 'Unknown stream') {
|
if (err && err !== 'Unknown stream') {
|
||||||
this._error(err);
|
this._error(err);
|
||||||
return;
|
return;
|
||||||
|
|
@ -16763,7 +16752,7 @@ FormData.prototype.submit = function(params, cb) {
|
||||||
request.removeListener('error', callback);
|
request.removeListener('error', callback);
|
||||||
request.removeListener('response', onResponse);
|
request.removeListener('response', onResponse);
|
||||||
|
|
||||||
return cb.call(this, error, responce);
|
return cb.call(this, error, responce); // eslint-disable-line no-invalid-this
|
||||||
};
|
};
|
||||||
|
|
||||||
onResponse = callback.bind(this, null);
|
onResponse = callback.bind(this, null);
|
||||||
|
|
@ -16776,7 +16765,7 @@ FormData.prototype.submit = function(params, cb) {
|
||||||
return request;
|
return request;
|
||||||
};
|
};
|
||||||
|
|
||||||
FormData.prototype._error = function(err) {
|
FormData.prototype._error = function (err) {
|
||||||
if (!this.error) {
|
if (!this.error) {
|
||||||
this.error = err;
|
this.error = err;
|
||||||
this.pause();
|
this.pause();
|
||||||
|
|
@ -16789,18 +16778,22 @@ FormData.prototype.toString = function () {
|
||||||
};
|
};
|
||||||
setToStringTag(FormData, 'FormData');
|
setToStringTag(FormData, 'FormData');
|
||||||
|
|
||||||
|
// Public API
|
||||||
|
module.exports = FormData;
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
|
|
||||||
/***/ 1835:
|
/***/ 1835:
|
||||||
/***/ ((module) => {
|
/***/ ((module) => {
|
||||||
|
|
||||||
// populates missing values
|
"use strict";
|
||||||
module.exports = function(dst, src) {
|
|
||||||
|
|
||||||
Object.keys(src).forEach(function(prop)
|
|
||||||
{
|
// populates missing values
|
||||||
dst[prop] = dst[prop] || src[prop];
|
module.exports = function (dst, src) {
|
||||||
|
Object.keys(src).forEach(function (prop) {
|
||||||
|
dst[prop] = dst[prop] || src[prop]; // eslint-disable-line no-param-reassign
|
||||||
});
|
});
|
||||||
|
|
||||||
return dst;
|
return dst;
|
||||||
|
|
|
||||||
15
package-lock.json
generated
15
package-lock.json
generated
|
|
@ -3778,14 +3778,14 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"node_modules/form-data": {
|
"node_modules/form-data": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz",
|
||||||
"integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==",
|
"integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==",
|
||||||
"license": "MIT",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"asynckit": "^0.4.0",
|
"asynckit": "^0.4.0",
|
||||||
"combined-stream": "^1.0.8",
|
"combined-stream": "^1.0.8",
|
||||||
"es-set-tostringtag": "^2.1.0",
|
"es-set-tostringtag": "^2.1.0",
|
||||||
|
"hasown": "^2.0.2",
|
||||||
"mime-types": "^2.1.12"
|
"mime-types": "^2.1.12"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|
@ -10210,13 +10210,14 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"form-data": {
|
"form-data": {
|
||||||
"version": "4.0.2",
|
"version": "4.0.4",
|
||||||
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.4.tgz",
|
||||||
"integrity": "sha512-hGfm/slu0ZabnNt4oaRZ6uREyfCj6P4fT/n6A1rGV+Z0VdGXjfOhVUpkn6qVQONHGIFwmveGXyDs75+nr6FM8w==",
|
"integrity": "sha512-KrGhL9Q4zjj0kiUt5OO4Mr/A/jlI2jDYs5eHBpYHPcBEVSiipAvn2Ko2HnPe20rmcuuvMHNdZFp+4IlGTMF0Ow==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"asynckit": "^0.4.0",
|
"asynckit": "^0.4.0",
|
||||||
"combined-stream": "^1.0.8",
|
"combined-stream": "^1.0.8",
|
||||||
"es-set-tostringtag": "^2.1.0",
|
"es-set-tostringtag": "^2.1.0",
|
||||||
|
"hasown": "^2.0.2",
|
||||||
"mime-types": "^2.1.12"
|
"mime-types": "^2.1.12"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue