2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-05-29 03:06:56 -04:00
|
|
|
require('../common');
|
2010-12-04 15:20:34 -08:00
|
|
|
var assert = require('assert');
|
|
|
|
var http = require('http');
|
|
|
|
var net = require('net');
|
2010-05-03 11:23:36 -07:00
|
|
|
|
2010-12-06 01:33:52 +03:00
|
|
|
var server = http.createServer(function(req, res) {
|
|
|
|
throw new Error('This shouldn\'t happen.');
|
2010-05-03 11:23:36 -07:00
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
server.on('upgrade', function(req, socket, upgradeHead) {
|
2010-06-29 23:12:46 -07:00
|
|
|
// test that throwing an error from upgrade gets
|
2010-05-20 15:21:40 -07:00
|
|
|
// is uncaught
|
2010-05-03 11:23:36 -07:00
|
|
|
throw new Error('upgrade error');
|
|
|
|
});
|
|
|
|
|
2010-12-04 16:11:57 -08:00
|
|
|
var gotError = false;
|
2010-05-03 11:23:36 -07:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
process.on('uncaughtException', function(e) {
|
2010-05-03 11:23:36 -07:00
|
|
|
assert.equal('upgrade error', e.message);
|
|
|
|
gotError = true;
|
2010-05-20 15:21:40 -07:00
|
|
|
process.exit(0);
|
2010-05-03 11:23:36 -07:00
|
|
|
});
|
|
|
|
|
2010-05-20 15:21:40 -07:00
|
|
|
|
2016-05-29 03:06:56 -04:00
|
|
|
server.listen(0, function() {
|
|
|
|
var c = net.createConnection(this.address().port);
|
2010-05-03 11:23:36 -07:00
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
c.on('connect', function() {
|
2010-12-06 01:33:52 +03:00
|
|
|
c.write('GET /blah HTTP/1.1\r\n' +
|
|
|
|
'Upgrade: WebSocket\r\n' +
|
|
|
|
'Connection: Upgrade\r\n' +
|
|
|
|
'\r\n\r\nhello world');
|
2010-05-03 11:23:36 -07:00
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
c.on('end', function() {
|
2010-05-03 11:23:36 -07:00
|
|
|
c.end();
|
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
c.on('close', function() {
|
2010-05-03 11:23:36 -07:00
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2011-10-15 01:08:36 +02:00
|
|
|
process.on('exit', function() {
|
2010-05-03 11:23:36 -07:00
|
|
|
assert.ok(gotError);
|
|
|
|
});
|