|
@ -12,51 +12,55 @@ server.on('upgrade', function(req, socket, head) { |
|
|
socket.end(); |
|
|
socket.end(); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
}); |
|
|
server.listen(8000); |
|
|
|
|
|
|
|
|
|
|
|
var client = http.createClient(8000); |
|
|
|
|
|
|
|
|
|
|
|
function upgradeRequest(fn) { |
|
|
server.listen(common.PORT, function () { |
|
|
var request = client.request('GET', '/', { |
|
|
|
|
|
'Connection': 'Upgrade', |
|
|
|
|
|
'Upgrade': 'Test' |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
var wasUpgrade = false; |
|
|
var client = http.createClient(common.PORT); |
|
|
|
|
|
|
|
|
function onUpgrade(res, socket, head) { |
|
|
function upgradeRequest(fn) { |
|
|
wasUpgrade = true; |
|
|
var request = client.request('GET', '/', { |
|
|
|
|
|
'Connection': 'Upgrade', |
|
|
|
|
|
'Upgrade': 'Test' |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
client.removeListener('upgrade', onUpgrade); |
|
|
var wasUpgrade = false; |
|
|
socket.end(); |
|
|
|
|
|
} |
|
|
|
|
|
client.on('upgrade', onUpgrade); |
|
|
|
|
|
|
|
|
|
|
|
function onEnd() { |
|
|
function onUpgrade(res, socket, head) { |
|
|
client.removeListener('end', onEnd); |
|
|
wasUpgrade = true; |
|
|
if (!wasUpgrade) { |
|
|
|
|
|
throw new Error('hasn\'t received upgrade event'); |
|
|
client.removeListener('upgrade', onUpgrade); |
|
|
} else { |
|
|
socket.end(); |
|
|
fn && process.nextTick(fn); |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
client.on('upgrade', onUpgrade); |
|
|
client.on('end', onEnd); |
|
|
|
|
|
|
|
|
|
|
|
request.write('head'); |
|
|
function onEnd() { |
|
|
|
|
|
client.removeListener('end', onEnd); |
|
|
|
|
|
if (!wasUpgrade) { |
|
|
|
|
|
throw new Error('hasn\'t received upgrade event'); |
|
|
|
|
|
} else { |
|
|
|
|
|
fn && process.nextTick(fn); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
client.on('end', onEnd); |
|
|
|
|
|
|
|
|
|
|
|
request.write('head'); |
|
|
|
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
successCount = 0; |
|
|
successCount = 0; |
|
|
upgradeRequest(function() { |
|
|
|
|
|
successCount++; |
|
|
|
|
|
upgradeRequest(function() { |
|
|
upgradeRequest(function() { |
|
|
successCount++; |
|
|
successCount++; |
|
|
// Test pass
|
|
|
upgradeRequest(function() { |
|
|
console.log('Pass!'); |
|
|
successCount++; |
|
|
client.end(); |
|
|
// Test pass
|
|
|
client.destroy(); |
|
|
console.log('Pass!'); |
|
|
server.close(); |
|
|
client.end(); |
|
|
|
|
|
client.destroy(); |
|
|
|
|
|
server.close(); |
|
|
|
|
|
}); |
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
}); |
|
|
}); |
|
|
|
|
|
|
|
|
process.on('exit', function () { |
|
|
process.on('exit', function () { |
|
|