make sure we don't overwrite existing content-length
This commit is contained in:
parent
c22bfa8189
commit
cfe98cdd35
4
index.js
4
index.js
|
@ -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));
|
||||
}
|
||||
|
||||
|
|
14
test/test.js
14
test/test.js
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue