From 05f40ee54c3aa5f4df5e727be6e5fdd16d90988d Mon Sep 17 00:00:00 2001 From: damian Date: Sat, 15 Sep 2018 09:55:08 +0200 Subject: [PATCH] won't set Content-Type header when body is not preset - setting Content-Type:'application/json' is confusing when there is no body in the request --- index.js | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/index.js b/index.js index a1ba973..339c2b0 100644 --- a/index.js +++ b/index.js @@ -16,10 +16,15 @@ opts.headers = opts.headers || {} opts.responseAs = (opts.responseAs && ['json', 'text', 'response'].indexOf(opts.responseAs) >= 0) ? opts.responseAs : 'json' - defaults(opts.headers, { - 'Accept': 'application/json', - 'Content-Type': 'application/json' - }) + var defaultHeaders = { + 'Accept': 'application/json' + }; + + if (!!data) { + defaultHeaders['Content-Type'] = 'application/json' + } + + defaults(opts.headers, defaultHeaders) if (queryParams) { url += getQuery(queryParams)