Browse Source

extract the key lowercasing to a separate module

https://github.com/sindresorhus/lowercase-keys
http2
Sindre Sorhus 10 years ago
parent
commit
e91768606c
  1. 23
      index.js
  2. 1
      package.json

23
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;

1
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",

Loading…
Cancel
Save