diff -Nru node-form-data-3.0.1/debian/changelog node-form-data-4.0.0/debian/changelog --- node-form-data-3.0.1/debian/changelog 2021-12-28 12:44:00.000000000 +0000 +++ node-form-data-4.0.0/debian/changelog 2022-07-17 08:20:30.000000000 +0000 @@ -1,3 +1,11 @@ +node-form-data (4.0.0-1) unstable; urgency=medium + + * Team upload + * Declare compliance with policy 4.6.1 + * New upstream version 4.0.0 + + -- Yadd Sun, 17 Jul 2022 10:20:30 +0200 + node-form-data (3.0.1-1) unstable; urgency=medium * Team upload diff -Nru node-form-data-3.0.1/debian/control node-form-data-4.0.0/debian/control --- node-form-data-3.0.1/debian/control 2021-12-28 11:50:35.000000000 +0000 +++ node-form-data-4.0.0/debian/control 2022-07-17 08:18:08.000000000 +0000 @@ -11,7 +11,7 @@ , node-combined-stream , node-formidable , node-mime-types -Standards-Version: 4.6.0 +Standards-Version: 4.6.1 Vcs-Browser: https://salsa.debian.org/js-team/node-form-data Vcs-Git: https://salsa.debian.org/js-team/node-form-data.git Homepage: https://github.com/felixge/node-form-data diff -Nru node-form-data-3.0.1/lib/form_data.js node-form-data-4.0.0/lib/form_data.js --- node-form-data-3.0.1/lib/form_data.js 2021-02-15 17:33:21.000000000 +0000 +++ node-form-data-4.0.0/lib/form_data.js 2021-02-15 17:36:47.000000000 +0000 @@ -5,6 +5,7 @@ var https = require('https'); var parseUrl = require('url').parse; var fs = require('fs'); +var Stream = require('stream').Stream; var mime = require('mime-types'); var asynckit = require('asynckit'); var populate = require('./populate.js'); @@ -100,8 +101,8 @@ Buffer.byteLength(header) + FormData.LINE_BREAK.length; - // empty or either doesn't have path or not an http response - if (!value || ( !value.path && !(value.readable && value.hasOwnProperty('httpVersion')) )) { + // empty or either doesn't have path or not an http response or not a stream + if (!value || ( !value.path && !(value.readable && value.hasOwnProperty('httpVersion')) && !(value instanceof Stream))) { return; } @@ -456,13 +457,15 @@ // get content length and fire away this.getLength(function(err, length) { - if (err) { + if (err && err !== 'Unknown stream') { this._error(err); return; } // add content length - request.setHeader('Content-Length', length); + if (length) { + request.setHeader('Content-Length', length); + } this.pipe(request); if (cb) { diff -Nru node-form-data-3.0.1/package.json node-form-data-4.0.0/package.json --- node-form-data-3.0.1/package.json 2021-02-15 17:33:21.000000000 +0000 +++ node-form-data-4.0.0/package.json 2021-02-15 17:36:47.000000000 +0000 @@ -2,7 +2,7 @@ "author": "Felix Geisendörfer (http://debuggable.com/)", "name": "form-data", "description": "A library to create readable \"multipart/form-data\" streams. Can be used to submit forms and file uploads to other web applications.", - "version": "3.0.1", + "version": "4.0.0", "repository": { "type": "git", "url": "git://github.com/form-data/form-data.git" diff -Nru node-form-data-3.0.1/Readme.md node-form-data-4.0.0/Readme.md --- node-form-data-3.0.1/Readme.md 2021-02-15 17:33:21.000000000 +0000 +++ node-form-data-4.0.0/Readme.md 2021-02-15 17:36:47.000000000 +0000 @@ -218,7 +218,7 @@ ``` #### _Headers_ getHeaders( [**Headers** _userHeaders_] ) -This method adds the correct `content-type` header to the provided array of `userHeaders`. +This method adds the correct `content-type` header to the provided array of `userHeaders`. #### _String_ getBoundary() Return the boundary of the formData. By default, the boundary consists of 26 `-` followed by 24 numbers @@ -348,6 +348,8 @@ ## Notes - ```getLengthSync()``` method DOESN'T calculate length for streams, use ```knownLength``` options as workaround. +- ```getLength(cb)``` will send an error as first parameter of callback if stream length cannot be calculated (e.g. send in custom streams w/o using ```knownLength```). +- ```submit``` will not add `content-length` if form length is unknown or not calculable. - Starting version `2.x` FormData has dropped support for `node@0.10.x`. - Starting version `3.x` FormData has dropped support for `node@4.x`. diff -Nru node-form-data-3.0.1/test/integration/test-form-get-length.js node-form-data-4.0.0/test/integration/test-form-get-length.js --- node-form-data-3.0.1/test/integration/test-form-get-length.js 2021-02-15 17:33:21.000000000 +0000 +++ node-form-data-4.0.0/test/integration/test-form-get-length.js 2021-02-15 17:36:47.000000000 +0000 @@ -3,6 +3,7 @@ var FormData = require(common.dir.lib + '/form_data'); var fake = require('fake').create(); var fs = require('fs'); +var Readable = require('stream').Readable; (function testEmptyForm() { var form = new FormData(); @@ -89,3 +90,40 @@ fake.expectAnytime(callback, [null, expectedLength]); form.getLength(callback); })(); + +(function testReadableStreamData() { + var form = new FormData(); + // var expectedLength = 0; + + var util = require('util'); + util.inherits(CustomReadable, Readable); + + /** + * Custion readable constructor + * @param {Object} opt options + * @constructor + */ + function CustomReadable(opt) { + Readable.call(this, opt); + this._max = 2; + this._index = 1; + } + + CustomReadable.prototype._read = function() { + var i = this._index++; + if (i > this._max) { + this.push(null); + } else { + this.push('' + i); + } + }; + form.append('my_txt', new CustomReadable()); + + // expectedLength += form._overheadLength + form._lastBoundary().length; + + // there is no way to determine the length of this readable stream. + var callback = fake.callback(arguments.callee.name + '-getLength'); + fake.expectAnytime(callback, ['Unknown stream', undefined]); + form.getLength(function(err, len) { callback(err,len); }); + +})(); diff -Nru node-form-data-3.0.1/test/integration/test-form-get-length-sync.js node-form-data-4.0.0/test/integration/test-form-get-length-sync.js --- node-form-data-3.0.1/test/integration/test-form-get-length-sync.js 2021-02-15 17:33:21.000000000 +0000 +++ node-form-data-4.0.0/test/integration/test-form-get-length-sync.js 2021-02-15 17:36:47.000000000 +0000 @@ -2,6 +2,7 @@ var assert = common.assert; var FormData = require(common.dir.lib + '/form_data'); var fs = require('fs'); +var Readable = require('stream').Readable; (function testGetLengthSync() { var fields = [ @@ -73,3 +74,34 @@ assert.equal(expectedLength, calculatedLength); })(); + +(function testReadableStreamData() { + var form = new FormData(); + + var util = require('util'); + util.inherits(CustomReadable, Readable); + + /** + * Custion readable constructor + * @param {Object} opt options + * @constructor + */ + function CustomReadable(opt) { + Readable.call(this, opt); + this._max = 2; + this._index = 1; + } + + CustomReadable.prototype._read = function() { + var i = this._index++; + if (i > this._max) { + this.push(null); + } else { + this.push('' + i); + } + }; + form.append('my_txt', new CustomReadable()); + + assert.throws(function() { form.getLengthSync(); }, /Cannot calculate proper length in synchronous way/); + +})(); diff -Nru node-form-data-3.0.1/test/integration/test-submit-readable-stream.js node-form-data-4.0.0/test/integration/test-submit-readable-stream.js --- node-form-data-3.0.1/test/integration/test-submit-readable-stream.js 1970-01-01 00:00:00.000000000 +0000 +++ node-form-data-4.0.0/test/integration/test-submit-readable-stream.js 2021-02-15 17:36:47.000000000 +0000 @@ -0,0 +1,54 @@ +var common = require('../common'); +var assert = common.assert; +var http = require('http'); +var FormData = require(common.dir.lib + '/form_data'); +var Readable = require('stream').Readable; + +var server = http.createServer(function(req, res) { + assert.strictEqual(req.headers['Content-Length'], undefined); + res.writeHead(200); + res.end('done'); +}); + +server.listen(common.port, function() { + var form = new FormData(); + + var util = require('util'); + util.inherits(CustomReadable, Readable); + + /** + * Custion readable constructor + * @param {Object} opt options + * @constructor + */ + function CustomReadable(opt) { + Readable.call(this, opt); + this._max = 2; + this._index = 1; + } + + CustomReadable.prototype._read = function() { + var i = this._index++; + // console.error('send back read data'); + if (i > this._max) { + this.push(null); + } else { + this.push('' + i); + } + }; + form.append('readable', new CustomReadable()); + + form.submit('http://localhost:' + common.port + '/', function(err, res) { + if (err) { + throw err; + } + + assert.strictEqual(res.statusCode, 200); + + // unstuck new streams + res.resume(); + + server.close(); + }); + +});