|
@ -64,8 +64,8 @@ var proxy = net.createServer(function(clientSocket) { |
|
|
if (!serverSocket) { |
|
|
if (!serverSocket) { |
|
|
// Verify the CONNECT request
|
|
|
// Verify the CONNECT request
|
|
|
assert.equal('CONNECT localhost:' + common.PORT + ' HTTP/1.1\r\n' + |
|
|
assert.equal('CONNECT localhost:' + common.PORT + ' HTTP/1.1\r\n' + |
|
|
'Proxy-Connections: keep-alive\r\nContent-Length:' + |
|
|
'Proxy-Connections: keep-alive\r\n' + |
|
|
' 0\r\nHost: localhost:' + proxyPort + '\r\n\r\n', |
|
|
'Host: localhost:' + proxyPort + '\r\n\r\n', |
|
|
chunk); |
|
|
chunk); |
|
|
|
|
|
|
|
|
console.log('PROXY: got CONNECT request'); |
|
|
console.log('PROXY: got CONNECT request'); |
|
@ -103,28 +103,45 @@ server.listen(common.PORT); |
|
|
proxy.listen(proxyPort, function() { |
|
|
proxy.listen(proxyPort, function() { |
|
|
console.log('CLIENT: Making CONNECT request'); |
|
|
console.log('CLIENT: Making CONNECT request'); |
|
|
|
|
|
|
|
|
http.request({ |
|
|
var req = http.request({ |
|
|
port: proxyPort, |
|
|
port: proxyPort, |
|
|
method: 'CONNECT', |
|
|
method: 'CONNECT', |
|
|
path: 'localhost:' + common.PORT, |
|
|
path: 'localhost:' + common.PORT, |
|
|
headers: { |
|
|
headers: { |
|
|
'Proxy-Connections': 'keep-alive', |
|
|
'Proxy-Connections': 'keep-alive' |
|
|
'Content-Length': 0 |
|
|
|
|
|
} |
|
|
} |
|
|
}, function(res) { |
|
|
}); |
|
|
|
|
|
req.useChunkedEncodingByDefault = false; // for v0.6
|
|
|
|
|
|
req.on('response', onResponse); // for v0.6
|
|
|
|
|
|
req.on('upgrade', onUpgrade); // for v0.6
|
|
|
|
|
|
req.on('connect', onConnect); // for v0.7 or later
|
|
|
|
|
|
req.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, header) { |
|
|
assert.equal(200, res.statusCode); |
|
|
assert.equal(200, res.statusCode); |
|
|
console.log('CLIENT: got CONNECT response'); |
|
|
console.log('CLIENT: got CONNECT response'); |
|
|
|
|
|
|
|
|
// detach the socket
|
|
|
// detach the socket
|
|
|
res.socket.emit('agentRemove'); |
|
|
socket.removeAllListeners('data'); |
|
|
res.socket.removeAllListeners('data'); |
|
|
socket.removeAllListeners('close'); |
|
|
res.socket.removeAllListeners('close'); |
|
|
socket.removeAllListeners('error'); |
|
|
res.socket.removeAllListeners('error'); |
|
|
socket.removeAllListeners('drain'); |
|
|
res.socket.removeAllListeners('drain'); |
|
|
socket.removeAllListeners('end'); |
|
|
res.socket.removeAllListeners('end'); |
|
|
socket.ondata = null; |
|
|
res.socket.ondata = null; |
|
|
socket.onend = null; |
|
|
res.socket.onend = null; |
|
|
socket.ondrain = null; |
|
|
res.socket.ondrain = null; |
|
|
|
|
|
|
|
|
|
|
|
console.log('CLIENT: Making HTTPS request'); |
|
|
console.log('CLIENT: Making HTTPS request'); |
|
|
|
|
|
|
|
@ -132,7 +149,7 @@ proxy.listen(proxyPort, function() { |
|
|
path: '/foo', |
|
|
path: '/foo', |
|
|
key: key, |
|
|
key: key, |
|
|
cert: cert, |
|
|
cert: cert, |
|
|
socket: res.socket, // reuse the socket
|
|
|
socket: socket, // reuse the socket
|
|
|
agent: false |
|
|
agent: false |
|
|
}, function(res) { |
|
|
}, function(res) { |
|
|
assert.equal(200, res.statusCode); |
|
|
assert.equal(200, res.statusCode); |
|
@ -148,7 +165,7 @@ proxy.listen(proxyPort, function() { |
|
|
server.close(); |
|
|
server.close(); |
|
|
}); |
|
|
}); |
|
|
}).end(); |
|
|
}).end(); |
|
|
}).end(); |
|
|
} |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
process.on('exit', function() { |
|
|
process.on('exit', function() { |
|
|