diff --git a/README.md b/README.md index 00f7d4f..99988c5 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,21 @@ got('http://localhost:9200', { }) ``` +### [needle](https://github.com/tomas/needle) + +```js +needle('get', 'http://localhost:9200', { + agent: new HttpProxyAgent({ + keepAlive: true, + keepAliveMsecs: 1000, + maxSockets: 256, + maxFreeSockets: 256, + scheduling: 'lifo', + proxy: 'http://localhost:8080' + }) +}) +``` + ## License This software is licensed under the [MIT](./LICENSE). diff --git a/package.json b/package.json index 11dee5c..3e58a3b 100644 --- a/package.json +++ b/package.json @@ -39,6 +39,7 @@ "devDependencies": { "ava": "^3.10.1", "got": "^11.5.1", + "needle": "^2.5.0", "proxy": "^1.0.2", "standard": "^14.3.4", "tsd": "^0.13.1" diff --git a/test/needle.test.js b/test/needle.test.js new file mode 100644 index 0000000..814d8a2 --- /dev/null +++ b/test/needle.test.js @@ -0,0 +1,103 @@ +'use strict' + +const needle = require('needle') +const test = require('ava') +const { + createServer, + createSecureServer, + createProxy, + createSecureProxy +} = require('./utils') +const { HttpProxyAgent, HttpsProxyAgent } = require('../') + +test('http to http', async t => { + const server = await createServer() + const proxy = await createProxy() + server.on('request', (req, res) => res.end('ok')) + + const response = await needle('get', `http://${server.address().address}:${server.address().port}`, { + agent: new HttpProxyAgent({ + keepAlive: true, + keepAliveMsecs: 1000, + maxSockets: 256, + maxFreeSockets: 256, + scheduling: 'lifo', + proxy: `http://${proxy.address().address}:${proxy.address().port}` + }) + }) + + t.is(response.body.toString(), 'ok') + t.is(response.statusCode, 200) + + server.close() + proxy.close() +}) + +test('https to http', async t => { + const server = await createServer() + const proxy = await createSecureProxy() + server.on('request', (req, res) => res.end('ok')) + + const response = await needle('get', `http://${server.address().address}:${server.address().port}`, { + agent: new HttpProxyAgent({ + keepAlive: true, + keepAliveMsecs: 1000, + maxSockets: 256, + maxFreeSockets: 256, + scheduling: 'lifo', + proxy: `https://${proxy.address().address}:${proxy.address().port}` + }) + }) + + t.is(response.body.toString(), 'ok') + t.is(response.statusCode, 200) + + server.close() + proxy.close() +}) + +test('http to https', async t => { + const server = await createSecureServer() + const proxy = await createProxy() + server.on('request', (req, res) => res.end('ok')) + + const response = await needle('get', `https://${server.address().address}:${server.address().port}`, { + agent: new HttpsProxyAgent({ + keepAlive: true, + keepAliveMsecs: 1000, + maxSockets: 256, + maxFreeSockets: 256, + scheduling: 'lifo', + proxy: `http://${proxy.address().address}:${proxy.address().port}` + }) + }) + + t.is(response.body.toString(), 'ok') + t.is(response.statusCode, 200) + + server.close() + proxy.close() +}) + +test('https to https', async t => { + const server = await createSecureServer() + const proxy = await createSecureProxy() + server.on('request', (req, res) => res.end('ok')) + + const response = await needle('get', `https://${server.address().address}:${server.address().port}`, { + agent: new HttpsProxyAgent({ + keepAlive: true, + keepAliveMsecs: 1000, + maxSockets: 256, + maxFreeSockets: 256, + scheduling: 'lifo', + proxy: `https://${proxy.address().address}:${proxy.address().port}` + }) + }) + + t.is(response.body.toString(), 'ok') + t.is(response.statusCode, 200) + + server.close() + proxy.close() +})