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');
console.log(res.headers);
var expectedHeaders = { "hello": "world"
, "connection": "upgrade"
, "upgrade": "websocket"
};
var expectedHeaders = { "hello": "world",
"connection": "upgrade",
"upgrade": "websocket" };
assert.deepEqual(expectedHeaders, res.headers);
socket.end();

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

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

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

@ -29,11 +29,10 @@ function testServer(){
});
server.addListener("upgrade", function(req, socket, upgradeHead){
socket.write( "HTTP/1.1 101 Web Socket Protocol Handshake\r\n"
+ "Upgrade: WebSocket\r\n"
+ "Connection: Upgrade\r\n"
+ "\r\n\r\n"
);
socket.write("HTTP/1.1 101 Web Socket Protocol Handshake\r\n" +
"Upgrade: WebSocket\r\n" +
"Connection: Upgrade\r\n" +
"\r\n\r\n");
request_upgradeHead = upgradeHead;
@ -66,13 +65,11 @@ function test_upgrade_with_listener(_server){
var state = 0;
conn.addListener("connect", function () {
writeReq( conn
, "GET / HTTP/1.1\r\n"
+ "Upgrade: WebSocket\r\n"
+ "Connection: Upgrade\r\n"
+ "\r\n"
+ "WjN}|M(6"
);
writeReq(conn, "GET / HTTP/1.1\r\n" +
"Upgrade: WebSocket\r\n" +
"Connection: Upgrade\r\n" +
"\r\n" +
"WjN}|M(6");
});
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 () {
common.error('client wrote message');
c.write( "GET /blah HTTP/1.1\r\n"
+ "Upgrade: WebSocket\r\n"
+ "Connection: Upgrade\r\n"
+ "\r\n\r\nhello world"
);
c.write("GET /blah HTTP/1.1\r\n" +
"Upgrade: WebSocket\r\n" +
"Connection: Upgrade\r\n" +
"\r\n\r\nhello world");
});
c.addListener('end', function () {

Loading…
Cancel
Save