postman-request
Advanced tools
Comparing version 2.88.1-postman.3-beta.1 to 2.88.1-postman.4-beta.1
@@ -175,44 +175,18 @@ 'use strict' | ||
var formData = {} | ||
var resetFormData = function (key, value) { | ||
var newValue | ||
var formValue = value && value.hasOwnProperty('value') ? value.value : value | ||
// if `formValue` is of type stream | ||
if (typeof formValue === 'object' && typeof formValue.pipe === 'function') { | ||
var formData = [] | ||
var resetFormData = function (key, value, paramOptions) { | ||
// if `value` is of type stream | ||
if (typeof (value && value.pipe) === 'function') { | ||
// bail out if not a file stream | ||
if (!(formValue.hasOwnProperty('fd') && formValue.path)) return | ||
if (!(value.hasOwnProperty('fd') && value.path)) return | ||
// create new file stream | ||
formValue = fs.createReadStream(formValue.path) | ||
value = fs.createReadStream(value.path) | ||
} | ||
if (value && value.hasOwnProperty('value') && value.hasOwnProperty('options')) { | ||
newValue = { value: formValue, options: value.options } | ||
} else { | ||
newValue = formValue | ||
} | ||
if (!formData.hasOwnProperty(key)) { | ||
formData[key] = newValue | ||
return | ||
} | ||
// at this point, we know that form has duplicate | ||
if (!Array.isArray(formData[key])) { | ||
formData[key] = [formData[key]] | ||
} | ||
formData[key].push(newValue) | ||
formData.push({key: key, value: value, options: paramOptions}) | ||
} | ||
for (var formKey in request.formData) { | ||
if (request.formData.hasOwnProperty(formKey)) { | ||
var formValue = request.formData[formKey] | ||
if (Array.isArray(formValue)) { | ||
for (var j = 0; j < formValue.length; j++) { | ||
resetFormData(formKey, formValue[j]) | ||
} | ||
} else { | ||
resetFormData(formKey, formValue) | ||
} | ||
} | ||
for (var i = 0, ii = request.formData.length; i < ii; i++) { | ||
var formParam = request.formData[i] | ||
if (!formParam) { continue } | ||
resetFormData(formParam.key, formParam.value, formParam.options) | ||
} | ||
@@ -219,0 +193,0 @@ |
@@ -10,3 +10,3 @@ { | ||
], | ||
"version": "2.88.1-postman.3-beta.1", | ||
"version": "2.88.1-postman.4-beta.1", | ||
"repository": { | ||
@@ -13,0 +13,0 @@ "type": "git", |
@@ -15,2 +15,3 @@ | ||
- Reinitialize FormData stream on 307 or 308 redirects | ||
- Respect form-data fields ordering | ||
@@ -17,0 +18,0 @@ ## Super simple to use |
@@ -74,2 +74,34 @@ 'use strict' | ||
function transformFormData (formData) { | ||
// Transform the object representation of form-data fields to array representation. | ||
// This might not preserve the order of form fields defined in object representation. | ||
// But, this transformation is required to support backward compatibility. | ||
// | ||
// Form-Data should be stored as an array to respect the fields order. | ||
// RFC 7578#section-5.2 Ordered Fields and Duplicated Field Names | ||
// https://tools.ietf.org/html/rfc7578#section-5.2 | ||
var transformedFormData = [] | ||
var appendFormParam = function (key, param) { | ||
transformedFormData.push({ | ||
key: key, | ||
value: param && param.hasOwnProperty('value') ? param.value : param, | ||
options: param && param.hasOwnProperty('options') ? param.options : undefined | ||
}) | ||
} | ||
for (var formKey in formData) { | ||
if (formData.hasOwnProperty(formKey)) { | ||
var formValue = formData[formKey] | ||
if (Array.isArray(formValue)) { | ||
for (var j = 0; j < formValue.length; j++) { | ||
appendFormParam(formKey, formValue[j]) | ||
} | ||
} else { | ||
appendFormParam(formKey, formValue) | ||
} | ||
} | ||
} | ||
return transformedFormData | ||
} | ||
// Return a simpler request object to allow serialization | ||
@@ -112,2 +144,8 @@ function requestToJSON () { | ||
// transform `formData` for backward compatibility | ||
// don't check for explicit object type to support legacy shenanigans | ||
if (options.formData && !Array.isArray(options.formData)) { | ||
options.formData = transformFormData(options.formData) | ||
} | ||
stream.Stream.call(self) | ||
@@ -348,21 +386,11 @@ var reserved = Object.keys(Request.prototype) | ||
var requestForm = self.form() | ||
var appendFormValue = function (key, value) { | ||
if (value && value.hasOwnProperty('value') && value.hasOwnProperty('options')) { | ||
requestForm.append(key, value.value, value.options) | ||
for (var i = 0, ii = formData.length; i < ii; i++) { | ||
var formParam = formData[i] | ||
if (!formParam) { continue } | ||
if (formParam.options) { | ||
requestForm.append(formParam.key, formParam.value, formParam.options) | ||
} else { | ||
requestForm.append(key, value) | ||
requestForm.append(formParam.key, formParam.value) | ||
} | ||
} | ||
for (var formKey in formData) { | ||
if (formData.hasOwnProperty(formKey)) { | ||
var formValue = formData[formKey] | ||
if (formValue instanceof Array) { | ||
for (var j = 0; j < formValue.length; j++) { | ||
appendFormValue(formKey, formValue[j]) | ||
} | ||
} else { | ||
appendFormValue(formKey, formValue) | ||
} | ||
} | ||
} | ||
} | ||
@@ -369,0 +397,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
217770
2798
1135
3