Browse Source

Style

v0.7.4-release
Ryan Dahl 14 years ago
parent
commit
3fceb491d4
  1. 7
      test/simple/test-http-upgrade-client.js
  2. 27
      test/simple/test-http-upgrade-client2.js
  3. 21
      test/simple/test-http-upgrade-server.js
  4. 9
      test/simple/test-http-upgrade-server2.js

7
test/simple/test-http-upgrade-client.js

@ -38,10 +38,9 @@ srv.listen(common.PORT, '127.0.0.1', function () {
assert.equal(upgradeHead, 'nurtzo'); assert.equal(upgradeHead, 'nurtzo');
console.log(res.headers); console.log(res.headers);
var expectedHeaders = { "hello": "world" var expectedHeaders = { "hello": "world",
, "connection": "upgrade" "connection": "upgrade",
, "upgrade": "websocket" "upgrade": "websocket" };
};
assert.deepEqual(expectedHeaders, res.headers); assert.deepEqual(expectedHeaders, res.headers);
socket.end(); socket.end();

27
test/simple/test-http-upgrade-client2.js

@ -4,12 +4,12 @@ var http = require('http'),
CRLF = '\r\n'; CRLF = '\r\n';
var server = http.createServer(); var server = http.createServer();
server.on('upgrade', function(req, socket, head) { server.on('upgrade', function(req, socket, head) {
socket.write('HTTP/1.1 101 Ok' + CRLF + socket.write('HTTP/1.1 101 Ok' + CRLF +
'Connection: Upgrade' + CRLF + 'Connection: Upgrade' + CRLF +
'Upgrade: Test' + CRLF + CRLF + 'head'); 'Upgrade: Test' + CRLF + CRLF + 'head');
socket.on('end', function () { socket.on('end', function () {
socket.end(); socket.end();
}); });
}); });
@ -19,40 +19,37 @@ server.listen(common.PORT, function () {
var client = http.createClient(common.PORT); var client = http.createClient(common.PORT);
function upgradeRequest(fn) { function upgradeRequest(fn) {
var request = client.request('GET', '/', { var header = { 'Connection': 'Upgrade', 'Upgrade': 'Test' };
'Connection': 'Upgrade', var request = client.request('GET', '/', header);
'Upgrade': 'Test'
});
var wasUpgrade = false; var wasUpgrade = false;
function onUpgrade(res, socket, head) { function onUpgrade(res, socket, head) {
wasUpgrade = true; wasUpgrade = true;
client.removeListener('upgrade', onUpgrade); client.removeListener('upgrade', onUpgrade);
socket.end(); socket.end();
} }
client.on('upgrade', onUpgrade); client.on('upgrade', onUpgrade);
function onEnd() { function onEnd() {
client.removeListener('end', onEnd); client.removeListener('end', onEnd);
if (!wasUpgrade) { if (!wasUpgrade) {
throw new Error('hasn\'t received upgrade event'); throw new Error('hasn\'t received upgrade event');
} else { } else {
fn && process.nextTick(fn); fn && process.nextTick(fn);
} }
} }
client.on('end', onEnd); client.on('end', onEnd);
request.write('head'); request.write('head');
} }
successCount = 0; successCount = 0;
upgradeRequest(function() { upgradeRequest(function() {
successCount++; successCount++;
upgradeRequest(function() { upgradeRequest(function() {
successCount++; successCount++;
// Test pass // Test pass
console.log('Pass!'); console.log('Pass!');
client.end(); client.end();

21
test/simple/test-http-upgrade-server.js

@ -29,11 +29,10 @@ function testServer(){
}); });
server.addListener("upgrade", function(req, socket, upgradeHead){ server.addListener("upgrade", function(req, socket, upgradeHead){
socket.write( "HTTP/1.1 101 Web Socket Protocol Handshake\r\n" socket.write("HTTP/1.1 101 Web Socket Protocol Handshake\r\n" +
+ "Upgrade: WebSocket\r\n" "Upgrade: WebSocket\r\n" +
+ "Connection: Upgrade\r\n" "Connection: Upgrade\r\n" +
+ "\r\n\r\n" "\r\n\r\n");
);
request_upgradeHead = upgradeHead; request_upgradeHead = upgradeHead;
@ -66,13 +65,11 @@ function test_upgrade_with_listener(_server){
var state = 0; var state = 0;
conn.addListener("connect", function () { conn.addListener("connect", function () {
writeReq( conn writeReq(conn, "GET / HTTP/1.1\r\n" +
, "GET / HTTP/1.1\r\n" "Upgrade: WebSocket\r\n" +
+ "Upgrade: WebSocket\r\n" "Connection: Upgrade\r\n" +
+ "Connection: Upgrade\r\n" "\r\n" +
+ "\r\n" "WjN}|M(6");
+ "WjN}|M(6"
);
}); });
conn.addListener("data", function (data) { conn.addListener("data", function (data) {

9
test/simple/test-http-upgrade-server2.js

@ -31,11 +31,10 @@ server.listen(common.PORT, function () {
c.addListener('connect', function () { c.addListener('connect', function () {
common.error('client wrote message'); common.error('client wrote message');
c.write( "GET /blah HTTP/1.1\r\n" c.write("GET /blah HTTP/1.1\r\n" +
+ "Upgrade: WebSocket\r\n" "Upgrade: WebSocket\r\n" +
+ "Connection: Upgrade\r\n" "Connection: Upgrade\r\n" +
+ "\r\n\r\nhello world" "\r\n\r\nhello world");
);
}); });
c.addListener('end', function () { c.addListener('end', function () {

Loading…
Cancel
Save