testing both form-data 1.x and 2.x support

This commit is contained in:
David Frank 2016-09-26 12:58:04 +08:00
parent b2e6cca648
commit 523a6920aa
3 changed files with 14 additions and 3 deletions

View File

@ -3,5 +3,10 @@ node_js:
- "0.10"
- "0.12"
- "node"
env:
- FORMDATA_VERSION=1.0.0
- FORMDATA_VERSION=2.1.0
before_script:
- 'if [ "$FORMDATA_VERSION" ]; then npm install form-data@^$FORMDATA_VERSION; fi'
before_install: npm install -g npm
script: npm run coverage

View File

@ -94,8 +94,14 @@ function Fetch(url, opts) {
if (typeof options.body === 'string') {
headers.set('content-length', Buffer.byteLength(options.body));
// detect form data input from form-data module, this hack avoid the need to add content-length header manually
} else if (options.body && typeof options.body.getLengthSync === 'function' && options.body._lengthRetrievers.length == 0) {
headers.set('content-length', options.body.getLengthSync().toString());
} else if (options.body && typeof options.body.getLengthSync === 'function') {
// for form-data 1.x
if (options.body._lengthRetrievers && options.body._lengthRetrievers.length == 0) {
headers.set('content-length', options.body.getLengthSync().toString());
// for form-data 2.x
} else if (options.body.hasKnownLength && options.body.hasKnownLength()) {
headers.set('content-length', options.body.getLengthSync().toString());
}
// this is only necessary for older nodejs releases (before iojs merge)
} else if (options.body === undefined || options.body === null) {
headers.set('content-length', '0');

View File

@ -28,7 +28,7 @@
"chai": "^3.5.0",
"chai-as-promised": "^5.2.0",
"coveralls": "^2.11.2",
"form-data": "^1.0.0-rc1",
"form-data": "^1.0.0",
"istanbul": "^0.4.2",
"mocha": "^2.1.0",
"parted": "^0.1.1",