Browse Source

Merge pull request #33 from kevva/tweaks

Various tweaks
http2
Sindre Sorhus 10 years ago
parent
commit
50d5f1aa9c
  1. 18
      index.js

18
index.js

@ -13,19 +13,18 @@ var prependHttp = require('prepend-http');
function got(url, opts, cb) { function got(url, opts, cb) {
if (typeof opts === 'function') { if (typeof opts === 'function') {
// if `cb` has been specified but `opts` has not
cb = opts; cb = opts;
opts = {}; opts = {};
} else if (!opts) { } else if (!opts) {
// opts has not been specified
opts = {}; opts = {};
} }
// extract own options
var encoding = opts.encoding; var encoding = opts.encoding;
delete opts.encoding;
var body = opts.body; var body = opts.body;
var proxy;
var redirectCount = 0;
delete opts.encoding;
delete opts.body; delete opts.body;
if (body) { if (body) {
@ -34,7 +33,6 @@ function got(url, opts, cb) {
// returns a proxy stream to the response // returns a proxy stream to the response
// if no callback has been provided // if no callback has been provided
var proxy;
if (!cb) { if (!cb) {
proxy = duplexify(); proxy = duplexify();
@ -44,15 +42,12 @@ function got(url, opts, cb) {
}; };
} }
// merge additional headers
opts.headers = assign({ opts.headers = assign({
'user-agent': 'https://github.com/sindresorhus/got', 'user-agent': 'https://github.com/sindresorhus/got',
'accept-encoding': 'gzip,deflate' 'accept-encoding': 'gzip,deflate'
}, opts.headers || {}); }, opts.headers || {});
var redirectCount = 0; function get(url, opts, cb) {
var get = function (url, opts, cb) {
var parsedUrl = urlLib.parse(prependHttp(url)); var parsedUrl = urlLib.parse(prependHttp(url));
var fn = parsedUrl.protocol === 'https:' ? https : http; var fn = parsedUrl.protocol === 'https:' ? https : http;
var arg = assign({}, parsedUrl, opts); var arg = assign({}, parsedUrl, opts);
@ -127,10 +122,9 @@ function got(url, opts, cb) {
} }
req.end(); req.end();
}; }
get(url, opts, cb); get(url, opts, cb);
return proxy; return proxy;
} }

Loading…
Cancel
Save