Skip to content

Instantly share code, notes, and snippets.

@kapouer
Last active December 29, 2015 07:19
Show Gist options
  • Select an option

  • Save kapouer/7634923 to your computer and use it in GitHub Desktop.

Select an option

Save kapouer/7634923 to your computer and use it in GitHub Desktop.
GH-177 test cooking
require('./common');
var http = require('http');
var server = http.createServer();
server.listen();
var engine = eio.attach(server, {
allowUpgrades: true,
transports: ['polling', 'websocket'],
pingInterval:4000,
pingTimeout: 8000
});
// disable websocket support
server.removeAllListeners('upgrade');
var port = server.address().port;
engine.on('connection', function (conn) {
setTimeout(function() {
conn.send('success');
}, 1000);
});
var socket = new eioc.Socket('ws://localhost:%d'.s(port));
socket.on('error', function(e) {
// fails before the fix
if (e.description) expect(e.description).to.not.be(400);
});
socket.on('open', function () {
// make sure we get the message after the fix
socket.on('message', function (msg) {
expect(msg).to.be('success');
done();
});
// squid, or nginx proxies remove Upgrade: websocket, Connection: Upgrade headers,
// transforming the ws request into http GET request.
// this emulates that bad behavior
var fakeProxyUrl = 'http://localhost:%d/engine.io/?EIO=2&transport=websocket&sid=%s'
.s(port, socket.id);
http.get(fakeProxyUrl);
});
@kapouer

kapouer commented Nov 25, 2013

Copy link
Copy Markdown
Author

This can be run in engine.io/test dir

@kapouer

kapouer commented Nov 25, 2013

Copy link
Copy Markdown
Author

Even if no race exists, be fair and listen messages before the fake GET.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment