request: formData: Maximum call stack size exceeded

Hey guys,

We are using your library in a project which sends a multipart body with an array of recipients. If the number of recipients is higher than 500 aprox, an exception is thrown. Check it out:

var request = require('request');

var array = [];
for (var i = 0; i < 500; i++) {
    array.push('data-' + i);
}

var data = {
    'array' : array
};

request.post({
  url: 'http://localhost:3000/example',
  formData: data
}, function (err, response, body) {
    if (err) console.error(err);
    console.log('All done.');
});

This returns the following error: RangeError: Maximum call stack size exceeded

We have been debugging the code and we think that the problem comes from request.js lin. 509:

   var appendFormValue = function (key, value) {
      if (value.hasOwnProperty('value') && value.hasOwnProperty('options')) {
        requestForm.append(key, value.value, value.options)
      } else {
        requestForm.append(key, 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)
        }
      }
    }

If you have any doubt, do not hesitate to let us know. Thanks in advance 😃

About this issue

  • Original URL
  • State: closed
  • Created 9 years ago
  • Reactions: 2
  • Comments: 17 (9 by maintainers)

Commits related to this issue

Most upvoted comments

@harryi3t @michalstanko I updated combined-stream with “always async” piping. And pulled it into form-data. Please try updated form-data with your local request and see if it solves the issue for you. Thank you.

New form-data version: form-data@2.3.2-rc1