testing both form-data 1.x and 2.x support
This commit is contained in:
parent
b2e6cca648
commit
523a6920aa
|
@ -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
|
10
index.js
10
index.js
|
@ -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');
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in New Issue