-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
119 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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() | ||
}) |