Browse Source

test: fix test-tls-over-http-tunnel with v0.7

v0.9.1-release
koichik 13 years ago
committed by isaacs
parent
commit
7ae0d473a6
  1. 51
      test/simple/test-tls-over-http-tunnel.js

51
test/simple/test-tls-over-http-tunnel.js

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

Loading…
Cancel
Save