diff --git a/index.js b/index.js index a49fa54..cef9b9d 100644 --- a/index.js +++ b/index.js @@ -10,22 +10,7 @@ var isStream = require('is-stream'); var read = require('read-all-stream'); var timeout = require('timed-out'); var prependHttp = require('prepend-http'); - -// prevent duplicates of different casing -function assignHeaders(val) { - val = val || {}; - - var ret = { - 'user-agent': 'https://github.com/sindresorhus/got', - 'accept-encoding': 'gzip,deflate' - }; - - Object.keys(val).forEach(function (el) { - ret[el.toLowerCase()] = val[el]; - }); - - return ret; -} +var lowercaseKeys = require('lowercase-keys'); function got(url, opts, cb) { if (typeof opts === 'function') { @@ -36,7 +21,11 @@ function got(url, opts, cb) { } opts = objectAssign({}, opts); - opts.headers = assignHeaders(opts.headers); + + opts.headers = objectAssign({ + 'user-agent': 'https://github.com/sindresorhus/got', + 'accept-encoding': 'gzip,deflate' + }, lowercaseKeys(opts.headers)); var encoding = opts.encoding; var body = opts.body; diff --git a/package.json b/package.json index 53907ee..4c0596d 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "duplexify": "^3.2.0", "infinity-agent": "^1.0.0", "is-stream": "^1.0.0", + "lowercase-keys": "^1.0.0", "object-assign": "^2.0.0", "prepend-http": "^1.0.0", "read-all-stream": "^1.0.0",