diff --git a/index.js b/index.js index 978572e..8024a38 100644 --- a/index.js +++ b/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); } diff --git a/test/test-post.js b/test/test-post.js index 8e2c61d..4196295 100644 --- a/test/test-post.js +++ b/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'); }); });