From 65b693bd80ee61259dd26f6fd372bf3d2d0cadb8 Mon Sep 17 00:00:00 2001 From: Sindre Sorhus Date: Mon, 5 Jan 2015 15:57:41 +0700 Subject: [PATCH] minor tweaks --- index.js | 9 ++++----- readme.md | 6 +++--- test/server.js | 5 ++++- test/test-gzip.js | 4 +--- test/test-http.js | 2 -- test/test-https.js | 17 +++++++++++------ test/test-post.js | 6 ++---- test/test-redirects.js | 2 -- 8 files changed, 25 insertions(+), 26 deletions(-) diff --git a/index.js b/index.js index 5bb6c05..74e4685 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,14 @@ 'use strict'; - +var http = require('http'); +var https = require('https'); +var urlLib = require('url'); +var zlib = require('zlib'); var assign = require('object-assign'); var agent = require('infinity-agent'); var duplexify = require('duplexify'); -var http = require('http'); -var https = require('https'); var isReadableStream = require('isstream').isReadable; var read = require('read-all-stream'); var timeout = require('timed-out'); -var urlLib = require('url'); -var zlib = require('zlib'); var prependHttp = require('prepend-http'); function got(url, opts, cb) { diff --git a/readme.md b/readme.md index 1bb9522..0a47496 100644 --- a/readme.md +++ b/readme.md @@ -79,9 +79,9 @@ Milliseconds after which the request will be aborted and an error event with `ET [http.Agent](http://nodejs.org/api/http.html#http_class_http_agent) instance. -Node HTTP/HTTPS [Agent in 0.10.35](https://github.com/joyent/node/blob/v0.10.35-release/lib/http.js#L1261) by default limits number of open sockets to 5 — which is a little low. By default got will use `new Agent({maxSockets: Infinity})` like new [Agent in 0.11.14](https://github.com/joyent/node/blob/v0.11.14-release/lib/_http_agent.js#L110). +Node HTTP/HTTPS [Agent in 0.10.35](https://github.com/joyent/node/blob/v0.10.35-release/lib/http.js#L1261) by default limits number of open sockets to 5 — which is a too low. By default `got` will use `new Agent({maxSockets: Infinity})` like new [`Agent` in 0.11.14](https://github.com/joyent/node/blob/v0.11.14-release/lib/_http_agent.js#L110). -You can read more about in [why pooling is evil](https://github.com/substack/hyperquest#pooling-is-evil). +[Why pooling is evil](https://github.com/substack/hyperquest#pooling-is-evil). To use default [globalAgent](http://nodejs.org/api/http.html#http_http_globalagent) just pass `null` to this option. @@ -118,7 +118,7 @@ var got = require('got'); var tunnel = require('tunnel'); got('todomvc.com', { - agent: tunnel.httpsOverHttp({ + agent: tunnel.httpOverHttp({ proxy: { host: 'localhost' } diff --git a/test/server.js b/test/server.js index 2b83a02..dd41bcb 100644 --- a/test/server.js +++ b/test/server.js @@ -1,5 +1,4 @@ 'use strict'; - var http = require('http'); var https = require('https'); @@ -8,12 +7,15 @@ exports.portSSL = 16167; exports.createServer = function (port) { port = port || exports.port; + var s = http.createServer(function (req, resp) { s.emit(req.url, req, resp); }); + s.port = port; s.url = 'http://localhost:' + port; s.protocol = 'http'; + return s; }; @@ -27,5 +29,6 @@ exports.createSSLServer = function (port, opts) { s.port = port; s.url = 'https://localhost:' + port; s.protocol = 'https'; + return s; }; diff --git a/test/test-gzip.js b/test/test-gzip.js index abf7098..9b5e3d7 100644 --- a/test/test-gzip.js +++ b/test/test-gzip.js @@ -1,10 +1,8 @@ 'use strict'; - +var zlib = require('zlib'); var tape = require('tape'); var got = require('../'); var server = require('./server.js'); -var zlib = require('zlib'); - var s = server.createServer(); var testContent = 'Compressible response content.\n'; diff --git a/test/test-http.js b/test/test-http.js index 631c88c..dca8a1b 100644 --- a/test/test-http.js +++ b/test/test-http.js @@ -1,9 +1,7 @@ 'use strict'; - var tape = require('tape'); var got = require('../'); var server = require('./server.js'); - var s = server.createServer(); s.on('/', function (req, res) { diff --git a/test/test-https.js b/test/test-https.js index 1a20193..e6ecd21 100644 --- a/test/test-https.js +++ b/test/test-https.js @@ -1,15 +1,20 @@ 'use strict'; - var tape = require('tape'); +var pem = require('pem'); var got = require('../'); var server = require('./server.js'); -var pem = require('pem'); - -var s, key, cert, caRootKey, caRootCert; +var s; +var key; +var cert; +var caRootKey; +var caRootCert; tape('root pem', function (t) { - pem.createCertificate({days:1, selfSigned:true}, function (err, keys) { + pem.createCertificate({ + days:1, + selfSigned:true + }, function (err, keys) { caRootKey = keys.serviceKey; caRootCert = keys.certificate; t.end(); @@ -64,7 +69,7 @@ tape('make request to https server with ca', function (t) { got(s.url, { strictSSL: true, ca: caRootCert, - headers: { host: 'sindresorhus.com' } + headers: {host: 'sindresorhus.com'} }, function (err, data) { t.error(err); t.equal(data, 'ok'); diff --git a/test/test-post.js b/test/test-post.js index 71f87e2..95ef569 100644 --- a/test/test-post.js +++ b/test/test-post.js @@ -1,10 +1,8 @@ 'use strict'; - var tape = require('tape'); +var from = require('from2-array'); var got = require('../'); var server = require('./server.js'); -var from = require('from2-array'); - var s = server.createServer(); s.on('/', function (req, res) { @@ -57,7 +55,7 @@ tape('throws on write to stream with body specified', function (t) { t.throws(function () { got(s.url, {body: 'wow'}).write('wow'); }); - setTimeout(t.end.bind(t), 10); // Wait for request to end + setTimeout(t.end.bind(t), 10); // wait for request to end }); tape('cleanup', function (t) { diff --git a/test/test-redirects.js b/test/test-redirects.js index 7fe18a2..a411e31 100644 --- a/test/test-redirects.js +++ b/test/test-redirects.js @@ -1,9 +1,7 @@ 'use strict'; - var tape = require('tape'); var got = require('../'); var server = require('./server.js'); - var s = server.createServer(); s.on('/finite', function (req, res) {