Browse Source

Do not override content-type when body is plain object

http2
Vsevolod Strukchinsky 10 years ago
parent
commit
e1cbaf200b
  1. 2
      index.js
  2. 8
      test/test-post.js

2
index.js

@ -206,7 +206,7 @@ function normalizeArguments(url, opts) {
opts.method = opts.method || 'POST';
if (isPlainObj(body)) {
opts.headers['content-type'] = 'application/x-www-form-urlencoded';
opts.headers['content-type'] = opts.headers['content-type'] || 'application/x-www-form-urlencoded';
body = opts.body = querystring.stringify(body);
}

8
test/test-post.js

@ -101,10 +101,16 @@ test('post have content-length header to string', function (t) {
});
test('works with plain object in body', function (t) {
t.plan(4);
got(s.url, {body: {such: 'wow'}}, function (err, data) {
t.error(err);
t.equal(data, 'such=wow');
t.end();
});
got(s.url + '/headers', {headers: {'content-type': 'doge'}, body: {such: 'wow'}, json: true}, function (err, headers) {
t.error(err);
t.equal(headers['content-type'], 'doge');
});
});

Loading…
Cancel
Save