Comparing version 0.0.0 to 0.0.1
@@ -13,4 +13,4 @@ 'use strict'; | ||
exports.httpOverHttp = httpOverHttp; | ||
exports.httpsOverHttp = httpsOverHttp; | ||
exports.httpOverHttps = httpOverHttps; | ||
exports.httpsOverHttp = httpsOverHttp; | ||
exports.httpsOverHttps = httpsOverHttps; | ||
@@ -25,12 +25,12 @@ | ||
function httpOverHttps(options) { | ||
function httpsOverHttp(options) { | ||
var agent = new TunnelingAgent(options); | ||
agent.request = https.request; | ||
agent.request = http.request; | ||
agent.createSocket = createSecureSocket; | ||
return agent; | ||
} | ||
function httpsOverHttp(options) { | ||
function httpOverHttps(options) { | ||
var agent = new TunnelingAgent(options); | ||
agent.request = http.request; | ||
agent.createSocket = createSecureSocket; | ||
agent.request = https.request; | ||
return agent; | ||
@@ -116,12 +116,31 @@ } | ||
} | ||
debug('making CONNECT request'); | ||
var connectReq = self.request(connectOptions); | ||
connectReq.once('connect', onConnect); | ||
connectReq.useChunkedEncodingByDefault = false; // for v0.6 | ||
connectReq.once('response', onResponse); // for v0.6 | ||
connectReq.once('upgrade', onUpgrade); // for v0.6 | ||
connectReq.once('connect', onConnect); // for v0.7 or later | ||
connectReq.once('error', onError); | ||
connectReq.end(); | ||
function onResponse(res) { | ||
// Very hacky. This is necessary to avoid http-parser leaks. | ||
res.upgrade = true; | ||
} | ||
function onUpgrade(res, socket, head) { | ||
// Hacky. | ||
process.nextTick(function() { | ||
onConnect(res, socket, head); | ||
}); | ||
} | ||
function onConnect(res, socket, head) { | ||
connectReq.removeListener('error', onError); | ||
connectReq.removeAllListeners(); | ||
socket.removeAllListeners(); | ||
if (res.statusCode === 200) { | ||
assert.equal(head.length, 0); | ||
debug('tunneling connection has established'); | ||
self.sockets[self.sockets.indexOf(placeholder)] = socket; | ||
@@ -141,3 +160,4 @@ cb(socket); | ||
function onError(cause) { | ||
connectReq.removeListener('connect', onConnect); | ||
connectReq.removeAllListeners(); | ||
debug('tunneling socket could not be established, cause=%s\n', | ||
@@ -173,3 +193,4 @@ cause.message, cause.stack); | ||
TunnelingAgent.prototype.createSocket.call(self, options, function(socket) { | ||
var secureSocket = tls.connect(mergeOptions({}, self.options, { | ||
// 0 is dummy port for v0.6 | ||
var secureSocket = tls.connect(0, mergeOptions({}, self.options, { | ||
socket: socket | ||
@@ -213,1 +234,2 @@ })); | ||
} | ||
exports.debug = debug; // for test |
{ | ||
"name": "tunnel", | ||
"version": "0.0.0", | ||
"version": "0.0.1", | ||
"description": "Node HTTP/HTTPS Agents for tunneling proxies", | ||
@@ -11,3 +11,3 @@ "keywords": [ | ||
], | ||
"homepage": "http://github.com/koichik/node-tunnel/", | ||
"homepage": "https://github.com/koichik/node-tunnel/", | ||
"author": "Koichi Kobayashi <koichik@improvement.jp>", | ||
@@ -21,3 +21,3 @@ "main": "./index.js", | ||
"engines": { | ||
"node": "0.7.0 || >=0.7.3" | ||
"node": ">=0.6.11 <=0.7.0 || >=0.7.3" | ||
}, | ||
@@ -24,0 +24,0 @@ "devDependencies": { |
@@ -17,3 +17,3 @@ # node-tunnel - HTTP/HTTPS Agents for tunneling proxies | ||
port: 443, | ||
agent = myAgent | ||
agent: myAgent | ||
}); | ||
@@ -29,3 +29,3 @@ | ||
var agent = tunnel.httpOverHttp({ | ||
var myAgent = tunnel.httpOverHttp({ | ||
maxSockets: poolSize, // Defaults to 5 | ||
@@ -55,3 +55,3 @@ | ||
var agent = tunnel.httpsOverHttp({ | ||
var myAgent = tunnel.httpsOverHttp({ | ||
maxSockets: poolSize, // Defaults to 5 | ||
@@ -88,3 +88,3 @@ | ||
var agent = tunnel.httpOverHttps({ | ||
var myAgent = tunnel.httpOverHttps({ | ||
maxSockets: poolSize, // Defaults to 5 | ||
@@ -121,3 +121,3 @@ | ||
var agent = tunnel.httpsOverHttps({ | ||
var myAgent = tunnel.httpsOverHttps({ | ||
maxSockets: poolSize, // Defaults to 5 | ||
@@ -124,0 +124,0 @@ |
@@ -15,16 +15,28 @@ var http = require('http'); | ||
var clientConnect = 0; | ||
var server; | ||
var proxy; | ||
var agent; | ||
var server = http.createServer(function(req, res) { | ||
server = http.createServer(function(req, res) { | ||
tunnel.debug('SERVER: got request'); | ||
++serverConnect; | ||
res.writeHead(200); | ||
res.end('Hello' + req.url); | ||
tunnel.debug('SERVER: sending response'); | ||
}); | ||
server.listen(serverPort, function() { | ||
var proxy = http.createServer(function(req, res) { | ||
server.listen(serverPort, setupProxy); | ||
function setupProxy() { | ||
proxy = http.createServer(function(req, res) { | ||
should.fail(); | ||
}); | ||
proxy.on('connect', function(req, clientSocket, head) { | ||
proxy.on('upgrade', onConnect); // for v0.6 | ||
proxy.on('connect', onConnect); // for v0.7 or later | ||
function onConnect(req, clientSocket, head) { | ||
tunnel.debug('PROXY: got CONNECT request'); | ||
req.method.should.equal('CONNECT'); | ||
req.url.should.equal('localhost:' + serverPort); | ||
req.headers.should.not.have.property('transfer-encoding'); | ||
req.headers.should.have.property('proxy-authorization', | ||
@@ -34,3 +46,5 @@ 'Basic ' + new Buffer('user:password').toString('base64')); | ||
tunnel.debug('PROXY: creating a tunnel'); | ||
var serverSocket = net.connect(serverPort, function() { | ||
tunnel.debug('PROXY: replying to client CONNECT request'); | ||
clientSocket.write('HTTP/1.1 200 Connection established\r\n\r\n'); | ||
@@ -45,36 +59,42 @@ clientSocket.pipe(serverSocket); | ||
}); | ||
} | ||
proxy.listen(proxyPort, setupClient); | ||
} | ||
function setupClient() { | ||
agent = tunnel.httpOverHttp({ | ||
maxSockets: poolSize, | ||
proxy: { | ||
port: proxyPort, | ||
proxyAuth: 'user:password' | ||
} | ||
}); | ||
proxy.listen(proxyPort, function() { | ||
agent = tunnel.httpOverHttp({ | ||
maxSockets: poolSize, | ||
proxy: { | ||
port: proxyPort, | ||
proxyAuth: 'user:password' | ||
} | ||
for (var i = 0; i < N; ++i) { | ||
doClientRequest(i); | ||
} | ||
function doClientRequest(i) { | ||
tunnel.debug('CLIENT: Making HTTP request (%d)', i); | ||
var req = http.get({ | ||
port: serverPort, | ||
path: '/' + i, | ||
agent: agent | ||
}, function(res) { | ||
tunnel.debug('CLIENT: got HTTP response (%d)', i); | ||
res.setEncoding('utf8'); | ||
res.on('data', function(data) { | ||
data.should.equal('Hello/' + i); | ||
}); | ||
res.on('end', function() { | ||
++clientConnect; | ||
if (clientConnect === N) { | ||
proxy.close(); | ||
server.close(); | ||
} | ||
}); | ||
}); | ||
for (var i = 0; i < N; ++i) { | ||
(function(i) { | ||
var req = http.get({ | ||
port: serverPort, | ||
path: '/' + i, | ||
agent: agent | ||
}, function(res) { | ||
res.setEncoding('utf8'); | ||
res.on('data', function(data) { | ||
data.should.equal('Hello/' + i); | ||
}); | ||
res.on('end', function() { | ||
++clientConnect; | ||
if (clientConnect === N) { | ||
proxy.close(); | ||
server.close(); | ||
} | ||
}); | ||
}); | ||
})(i); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
server.on('close', function() { | ||
@@ -81,0 +101,0 @@ serverConnect.should.equal(N); |
@@ -15,4 +15,4 @@ var http = require('http'); | ||
it('should finish without error', function(done) { | ||
var serverPort = 3002; | ||
var proxyPort = 3003; | ||
var serverPort = 3004; | ||
var proxyPort = 3005; | ||
var poolSize = 3; | ||
@@ -23,12 +23,17 @@ var N = 10; | ||
var clientConnect = 0; | ||
var server; | ||
var proxy; | ||
var agent; | ||
var server = http.createServer(function(req, res) { | ||
server = http.createServer(function(req, res) { | ||
tunnel.debug('SERVER: got request'); | ||
++serverConnect; | ||
res.writeHead(200); | ||
res.end('Hello' + req.url); | ||
tunnel.debug('SERVER: sending response'); | ||
}); | ||
server.listen(serverPort, function() { | ||
var proxy = https.createServer({ | ||
server.listen(serverPort, setupProxy); | ||
function setupProxy() { | ||
proxy = https.createServer({ | ||
key: readPem('agent4-key'), | ||
@@ -42,8 +47,16 @@ cert: readPem('agent4-cert'), | ||
}); | ||
proxy.on('connect', function(req, clientSocket, head) { | ||
proxy.on('upgrade', onConnect); // for v0.6 | ||
proxy.on('connect', onConnect); // for v0.7 or later | ||
function onConnect(req, clientSocket, head) { | ||
tunnel.debug('PROXY: got CONNECT request'); | ||
req.method.should.equal('CONNECT'); | ||
req.url.should.equal('localhost:' + serverPort); | ||
req.headers.should.not.have.property('transfer-encoding'); | ||
++proxyConnect; | ||
tunnel.debug('PROXY: creating a tunnel'); | ||
var serverSocket = net.connect(serverPort, function() { | ||
tunnel.debug('PROXY: replying to client CONNECT request'); | ||
clientSocket.write('HTTP/1.1 200 Connection established\r\n\r\n'); | ||
@@ -58,38 +71,44 @@ clientSocket.pipe(serverSocket); | ||
}); | ||
}); | ||
proxy.listen(proxyPort, function() { | ||
agent = tunnel.httpOverHttps({ | ||
maxSockets: poolSize, | ||
proxy: { | ||
port: proxyPort, | ||
// client certification for proxy | ||
key: readPem('agent3-key'), | ||
cert: readPem('agent3-cert') | ||
} | ||
}); | ||
} | ||
proxy.listen(proxyPort, setupClient); | ||
} | ||
for (var i = 0; i < N; ++i) { | ||
(function(i) { | ||
var req = http.get({ | ||
port: serverPort, | ||
path: '/' + i, | ||
agent: agent | ||
}, function(res) { | ||
res.setEncoding('utf8'); | ||
res.on('data', function(data) { | ||
data.should.equal('Hello/' + i); | ||
}); | ||
res.on('end', function() { | ||
++clientConnect; | ||
if (clientConnect === N) { | ||
proxy.close(); | ||
server.close(); | ||
} | ||
}); | ||
}); | ||
})(i); | ||
function setupClient() { | ||
agent = tunnel.httpOverHttps({ | ||
maxSockets: poolSize, | ||
proxy: { | ||
port: proxyPort, | ||
// client certification for proxy | ||
key: readPem('agent3-key'), | ||
cert: readPem('agent3-cert') | ||
} | ||
}); | ||
}); | ||
for (var i = 0; i < N; ++i) { | ||
doClientRequest(i); | ||
} | ||
function doClientRequest(i) { | ||
tunnel.debug('CLIENT: Making HTTP request (%d)', i); | ||
var req = http.get({ | ||
port: serverPort, | ||
path: '/' + i, | ||
agent: agent | ||
}, function(res) { | ||
tunnel.debug('CLIENT: got HTTP response (%d)', i); | ||
res.setEncoding('utf8'); | ||
res.on('data', function(data) { | ||
data.should.equal('Hello/' + i); | ||
}); | ||
res.on('end', function() { | ||
++clientConnect; | ||
if (clientConnect === N) { | ||
proxy.close(); | ||
server.close(); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
server.on('close', function() { | ||
@@ -96,0 +115,0 @@ serverConnect.should.equal(N); |
@@ -15,4 +15,4 @@ var http = require('http'); | ||
it('should finish without error', function(done) { | ||
var serverPort = 3004; | ||
var proxyPort = 3005; | ||
var serverPort = 3002; | ||
var proxyPort = 3003; | ||
var poolSize = 3; | ||
@@ -23,5 +23,7 @@ var N = 10; | ||
var clientConnect = 0; | ||
var server; | ||
var proxy; | ||
var agent; | ||
var server = https.createServer({ | ||
server = https.createServer({ | ||
key: readPem('agent2-key'), | ||
@@ -33,16 +35,27 @@ cert: readPem('agent2-cert'), | ||
}, function(req, res) { | ||
tunnel.debug('SERVER: got request'); | ||
++serverConnect; | ||
res.writeHead(200); | ||
res.end('Hello' + req.url); | ||
tunnel.debug('SERVER: sending response'); | ||
}); | ||
server.listen(serverPort, function() { | ||
var proxy = http.createServer(function(req, res) { | ||
server.listen(serverPort, setupProxy); | ||
function setupProxy() { | ||
proxy = http.createServer(function(req, res) { | ||
should.fail(); | ||
}); | ||
proxy.on('connect', function(req, clientSocket, head) { | ||
proxy.on('upgrade', onConnect); // for v0.6 | ||
proxy.on('connect', onConnect); // for v0.7 or later | ||
function onConnect(req, clientSocket, head) { | ||
tunnel.debug('PROXY: got CONNECT request'); | ||
req.method.should.equal('CONNECT'); | ||
req.url.should.equal('localhost:' + serverPort); | ||
req.headers.should.not.have.property('transfer-encoding'); | ||
++proxyConnect; | ||
var serverSocket = net.connect(serverPort, function() { | ||
tunnel.debug('PROXY: replying to client CONNECT request'); | ||
clientSocket.write('HTTP/1.1 200 Connection established\r\n\r\n'); | ||
@@ -57,38 +70,44 @@ clientSocket.pipe(serverSocket); | ||
}); | ||
}); | ||
proxy.listen(proxyPort, function() { | ||
agent = tunnel.httpsOverHttp({ | ||
maxSockets: poolSize, | ||
// client certification for origin server | ||
key: readPem('agent1-key'), | ||
cert: readPem('agent1-cert'), | ||
proxy: { | ||
port: proxyPort | ||
} | ||
}); | ||
} | ||
proxy.listen(proxyPort, setupClient); | ||
} | ||
for (var i = 0; i < N; ++i) { | ||
(function(i) { | ||
var req = https.get({ | ||
port: serverPort, | ||
path: '/' + i, | ||
agent: agent | ||
}, function(res) { | ||
res.setEncoding('utf8'); | ||
res.on('data', function(data) { | ||
data.should.equal('Hello/' + i); | ||
}); | ||
res.on('end', function() { | ||
++clientConnect; | ||
if (clientConnect === N) { | ||
proxy.close(); | ||
server.close(); | ||
} | ||
}); | ||
}); | ||
})(i); | ||
function setupClient() { | ||
agent = tunnel.httpsOverHttp({ | ||
maxSockets: poolSize, | ||
// client certification for origin server | ||
key: readPem('agent1-key'), | ||
cert: readPem('agent1-cert'), | ||
proxy: { | ||
port: proxyPort | ||
} | ||
}); | ||
}); | ||
for (var i = 0; i < N; ++i) { | ||
doClientRequest(i); | ||
} | ||
function doClientRequest(i) { | ||
tunnel.debug('CLIENT: Making HTTPS request (%d)', i); | ||
var req = https.get({ | ||
port: serverPort, | ||
path: '/' + i, | ||
agent: agent | ||
}, function(res) { | ||
tunnel.debug('CLIENT: got HTTPS response (%d)', i); | ||
res.setEncoding('utf8'); | ||
res.on('data', function(data) { | ||
data.should.equal('Hello/' + i); | ||
}); | ||
res.on('end', function() { | ||
++clientConnect; | ||
if (clientConnect === N) { | ||
proxy.close(); | ||
server.close(); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
server.on('close', function() { | ||
@@ -95,0 +114,0 @@ serverConnect.should.equal(N); |
@@ -21,4 +21,6 @@ var http = require('http'); | ||
var clientError = 0; | ||
var server = https.createServer({ | ||
var server; | ||
var proxy; | ||
server = https.createServer({ | ||
key: readPem('agent2-key'), | ||
@@ -30,8 +32,12 @@ cert: readPem('agent2-cert'), | ||
}, function(req, res) { | ||
tunnel.debug('SERVER: got request'); | ||
++serverConnect; | ||
res.writeHead(200); | ||
res.end('Hello, ' + serverConnect); | ||
tunnel.debug('SERVER: sending response'); | ||
}); | ||
server.listen(serverPort, function() { | ||
var proxy = https.createServer({ | ||
server.listen(serverPort, setupProxy); | ||
function setupProxy() { | ||
proxy = https.createServer({ | ||
key: readPem('agent4-key'), | ||
@@ -45,8 +51,13 @@ cert: readPem('agent4-cert'), | ||
}); | ||
proxy.on('connect', function(req, clientSocket, head) { | ||
proxy.on('upgrade', onConnect); // for v0.6 | ||
proxy.on('connect', onConnect); // for v0.7 or later | ||
function onConnect(req, clientSocket, head) { | ||
req.method.should.equal('CONNECT'); | ||
req.url.should.equal('localhost:' + serverPort); | ||
req.headers.should.not.have.property('transfer-encoding'); | ||
++proxyConnect; | ||
var serverSocket = net.connect(serverPort, function() { | ||
tunnel.debug('PROXY: replying to client CONNECT request'); | ||
clientSocket.write('HTTP/1.1 200 Connection established\r\n\r\n'); | ||
@@ -61,68 +72,73 @@ clientSocket.pipe(serverSocket); | ||
}); | ||
}); | ||
proxy.listen(proxyPort, function() { | ||
function doRequest(options) { | ||
var agent = tunnel.httpsOverHttps(options); | ||
var req = https.get({ | ||
port: serverPort, | ||
agent: agent | ||
}, function(res) { | ||
++clientConnect; | ||
req.emit('finish'); | ||
}); | ||
req.on('error', function(err) { | ||
++clientError; | ||
req.emit('finish'); | ||
}); | ||
req.on('finish', function() { | ||
if (clientConnect + clientError === 4) { | ||
proxy.close(); | ||
server.close(); | ||
} | ||
}); | ||
} | ||
doRequest({ // invalid | ||
maxSockets: 1, | ||
// no certificate for origin server | ||
proxy: { | ||
port: proxyPort | ||
// no certificate for proxy | ||
} | ||
} | ||
proxy.listen(proxyPort, setupClient); | ||
} | ||
function setupClient() { | ||
function doRequest(name, options) { | ||
tunnel.debug('CLIENT: Making HTTPS request (%s)', name); | ||
var agent = tunnel.httpsOverHttps(options); | ||
var req = https.get({ | ||
port: serverPort, | ||
agent: agent | ||
}, function(res) { | ||
tunnel.debug('CLIENT: got HTTPS response (%s)', name); | ||
++clientConnect; | ||
req.emit('finish'); | ||
}); | ||
doRequest({ // invalid | ||
maxSockets: 1, | ||
// client certification for origin server | ||
key: readPem('agent1-key'), | ||
cert: readPem('agent1-cert'), | ||
proxy: { | ||
port: proxyPort | ||
// no certificate for proxy | ||
} | ||
req.on('error', function(err) { | ||
tunnel.debug('CLIENT: failed HTTP response (%s)', name); | ||
++clientError; | ||
req.emit('finish'); | ||
}); | ||
doRequest({ // invalid | ||
maxSockets: 1, | ||
// no certificate for origin server | ||
proxy: { | ||
port: proxyPort, | ||
// client certification for proxy | ||
key: readPem('agent3-key'), | ||
cert: readPem('agent3-cert') | ||
req.on('finish', function() { | ||
if (clientConnect + clientError === 4) { | ||
proxy.close(); | ||
server.close(); | ||
} | ||
}); | ||
doRequest({ // valid | ||
maxSockets: 1, | ||
// client certification for origin server | ||
key: readPem('agent1-key'), | ||
cert: readPem('agent1-cert'), | ||
proxy: { | ||
port: proxyPort, | ||
// client certification for proxy | ||
key: readPem('agent3-key'), | ||
cert: readPem('agent3-cert') | ||
} | ||
}); | ||
} | ||
doRequest('no cert origin nor proxy', { // invalid | ||
maxSockets: 1, | ||
// no certificate for origin server | ||
proxy: { | ||
port: proxyPort | ||
// no certificate for proxy | ||
} | ||
}); | ||
}); | ||
doRequest('no cert proxy', { // invalid | ||
maxSockets: 1, | ||
// client certification for origin server | ||
key: readPem('agent1-key'), | ||
cert: readPem('agent1-cert'), | ||
proxy: { | ||
port: proxyPort | ||
// no certificate for proxy | ||
} | ||
}); | ||
doRequest('no cert origin', { // invalid | ||
maxSockets: 1, | ||
// no certificate for origin server | ||
proxy: { | ||
port: proxyPort, | ||
// client certification for proxy | ||
key: readPem('agent3-key'), | ||
cert: readPem('agent3-cert') | ||
} | ||
}); | ||
doRequest('valid', { // valid | ||
maxSockets: 1, | ||
// client certification for origin server | ||
key: readPem('agent1-key'), | ||
cert: readPem('agent1-cert'), | ||
proxy: { | ||
port: proxyPort, | ||
// client certification for proxy | ||
key: readPem('agent3-key'), | ||
cert: readPem('agent3-cert') | ||
} | ||
}); | ||
} | ||
server.on('close', function() { | ||
@@ -133,3 +149,3 @@ serverConnect.should.equal(1); | ||
clientError.should.equal(3); | ||
done(); | ||
@@ -136,0 +152,0 @@ }); |
@@ -22,5 +22,7 @@ var http = require('http'); | ||
var clientConnect = 0; | ||
var server; | ||
var proxy; | ||
var agent; | ||
var server = https.createServer({ | ||
server = https.createServer({ | ||
key: readPem('agent2-key'), | ||
@@ -32,8 +34,12 @@ cert: readPem('agent2-cert'), | ||
}, function(req, res) { | ||
tunnel.debug('SERVER: got request'); | ||
++serverConnect; | ||
res.writeHead(200); | ||
res.end('Hello' + req.url); | ||
tunnel.debug('SERVER: sending response'); | ||
}); | ||
server.listen(serverPort, function() { | ||
var proxy = https.createServer({ | ||
server.listen(serverPort, setupProxy); | ||
function setupProxy() { | ||
proxy = https.createServer({ | ||
key: readPem('agent4-key'), | ||
@@ -47,8 +53,14 @@ cert: readPem('agent4-cert'), | ||
}); | ||
proxy.on('connect', function(req, clientSocket, head) { | ||
proxy.on('upgrade', onConnect); // for v0.6 | ||
proxy.on('connect', onConnect); // for v0.7 or later | ||
function onConnect(req, clientSocket, head) { | ||
tunnel.debug('PROXY: got CONNECT request'); | ||
req.method.should.equal('CONNECT'); | ||
req.url.should.equal('localhost:' + serverPort); | ||
req.headers.should.not.have.property('transfer-encoding'); | ||
++proxyConnect; | ||
var serverSocket = net.connect(serverPort, function() { | ||
tunnel.debug('PROXY: replying to client CONNECT request'); | ||
clientSocket.write('HTTP/1.1 200 Connection established\r\n\r\n'); | ||
@@ -63,41 +75,47 @@ clientSocket.pipe(serverSocket); | ||
}); | ||
} | ||
proxy.listen(proxyPort, setupClient); | ||
} | ||
function setupClient() { | ||
agent = tunnel.httpsOverHttps({ | ||
maxSockets: poolSize, | ||
// client certification for origin server | ||
key: readPem('agent1-key'), | ||
cert: readPem('agent1-cert'), | ||
proxy: { | ||
port: proxyPort, | ||
// client certification for proxy | ||
key: readPem('agent3-key'), | ||
cert: readPem('agent3-cert') | ||
} | ||
}); | ||
proxy.listen(proxyPort, function() { | ||
agent = tunnel.httpsOverHttps({ | ||
maxSockets: poolSize, | ||
// client certification for origin server | ||
key: readPem('agent1-key'), | ||
cert: readPem('agent1-cert'), | ||
proxy: { | ||
port: proxyPort, | ||
// client certification for proxy | ||
key: readPem('agent3-key'), | ||
cert: readPem('agent3-cert') | ||
} | ||
for (var i = 0; i < N; ++i) { | ||
doClientRequest(i); | ||
} | ||
function doClientRequest(i) { | ||
tunnel.debug('CLIENT: Making HTTPS request (%d)', i); | ||
var req = https.get({ | ||
port: serverPort, | ||
path: '/' + i, | ||
agent: agent | ||
}, function(res) { | ||
tunnel.debug('CLIENT: got HTTPS response (%d)', i); | ||
res.setEncoding('utf8'); | ||
res.on('data', function(data) { | ||
data.should.equal('Hello/' + i); | ||
}); | ||
res.on('end', function() { | ||
++clientConnect; | ||
if (clientConnect === N) { | ||
proxy.close(); | ||
server.close(); | ||
} | ||
}); | ||
}); | ||
for (var i = 0; i < N; ++i) { | ||
(function(i) { | ||
var req = https.get({ | ||
port: serverPort, | ||
path: '/' + i, | ||
agent: agent | ||
}, function(res) { | ||
res.setEncoding('utf8'); | ||
res.on('data', function(data) { | ||
data.should.equal('Hello/' + i); | ||
}); | ||
res.on('end', function() { | ||
++clientConnect; | ||
if (clientConnect === N) { | ||
proxy.close(); | ||
server.close(); | ||
} | ||
}); | ||
}); | ||
})(i); | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
server.on('close', function() { | ||
@@ -107,3 +125,3 @@ serverConnect.should.equal(N); | ||
clientConnect.should.equal(N); | ||
var name = 'localhost:' + serverPort; | ||
@@ -110,0 +128,0 @@ agent.sockets.should.not.have.ownProperty(name); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48162
767