make sure we don't overwrite existing content-length

This commit is contained in:
David Frank 2015-09-28 19:27:57 +08:00
parent c22bfa8189
commit cfe98cdd35
2 changed files with 2 additions and 16 deletions

View File

@ -82,8 +82,8 @@ function Fetch(url, opts) {
headers.set('content-type', 'multipart/form-data; boundary=' + options.body.getBoundary());
}
// bring node-fetch closer to browser fetch behavior by setting content-length automatically for post, put, patch requests when body is string
if (options.method.substr(0, 1).toUpperCase() === 'P' && typeof options.body === 'string') {
// bring node-fetch closer to browser behavior by setting content-length automatically for POST, PUT, PATCH requests when body is string
if (!headers.has('content-length') && typeof options.body === 'string' && options.method.substr(0, 1).toUpperCase() === 'P') {
headers.set('content-length', Buffer.byteLength(options.body));
}

View File

@ -547,20 +547,6 @@ describe('node-fetch', function() {
});
});
it('should set request content-length when sending string as body', function() {
url = base + '/inspect';
opts = {
method: 'POST'
, body: 'a=1'
};
return fetch(url, opts).then(function(res) {
return res.json();
}).then(function(res) {
expect(res.method).to.equal('POST');
});
});
it('should reject decoding body twice', function() {
url = base + '/plain';
return fetch(url).then(function(res) {