Browse Source

minor tweaks

http2
Sindre Sorhus 10 years ago
parent
commit
65b693bd80
  1. 9
      index.js
  2. 6
      readme.md
  3. 5
      test/server.js
  4. 4
      test/test-gzip.js
  5. 2
      test/test-http.js
  6. 17
      test/test-https.js
  7. 6
      test/test-post.js
  8. 2
      test/test-redirects.js

9
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) {

6
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'
}

5
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;
};

4
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';

2
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) {

17
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');

6
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) {

2
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) {

Loading…
Cancel
Save