From e1cbaf200bada130ae4b68568c561ed5aff19cd3 Mon Sep 17 00:00:00 2001 From: Vsevolod Strukchinsky Date: Mon, 27 Jul 2015 16:08:30 +0500 Subject: [PATCH] Do not override content-type when body is plain object --- index.js | 2 +- test/test-post.js | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) 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'); }); });