}
}
- hs = spdy.createServer(opts, handleHttpRequest);
+ hs = spdy.createServer(opts);
hs.listen(web_config.port, web_config.address, function () {
that.emit('listening');
} else {
// Start some plain-text server up
- hs = http.createServer(handleHttpRequest);
+ hs = http.createServer();
hs.listen(web_config.port, web_config.address, function () {
that.emit('listening');
that.emit('error', err);
});
- this.ws = engine.attach(hs, {
- path: (global.config.http_base_path || '') + '/transport'
+ this.ws = new engine.Server();
+
+ hs.on('upgrade', function(req, socket, head){
+ that.ws.handleUpgrade(req, socket, head);
+ });
+
+ hs.on('request', function(req, res){
+ var transport_url = (global.config.http_base_path || '') + '/transport';
+
+ // engine.io can sometimes "loose" the clients remote address. Keep note of it
+ req.meta = {
+ remote_address: req.connection.remoteAddress
+ };
+
+ // If the request is for our transport, pass it onto engine.io
+ if (req.url.toLowerCase().indexOf(transport_url.toLowerCase()) === 0) {
+ that.ws.handleRequest(req, res);
+ } else {
+ http_handler.serve(req, res);
+ }
+
+
});
this.ws.on('connection', function(socket) {
-function handleHttpRequest(request, response) {
- http_handler.serve(request, response);
-}
-
function rangeCheck(addr, range) {
var i, ranges, parts;
ranges = (!_.isArray(range)) ? [range] : range;
*/
function initialiseSocket(socket, callback) {
var request = socket.request,
- address = request.connection.remoteAddress,
+ address = request.meta.remote_address,
revdns;
// Key/val data stored to the socket to be read later on
// May also be synced to a redis DB to lookup clients
- socket.meta = {};
+ socket.meta = socket.request.meta;
// If a forwarded-for header is found, switch the source address
if (request.headers[global.config.http_proxy_ip_header || 'x-forwarded-for']) {