08-27-周三_17-09-29
This commit is contained in:
73
node_modules/sockjs/lib/chunking-test.js
generated
vendored
Normal file
73
node_modules/sockjs/lib/chunking-test.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
(function() {
|
||||
var utils;
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
exports.app = {
|
||||
chunking_test: function(req, res, _, next_filter) {
|
||||
var write,
|
||||
_this = this;
|
||||
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
|
||||
res.writeHead(200);
|
||||
write = function(payload) {
|
||||
try {
|
||||
return res.write(payload + '\n');
|
||||
} catch (x) {
|
||||
|
||||
}
|
||||
};
|
||||
utils.timeout_chain([
|
||||
[
|
||||
0, function() {
|
||||
return write('h');
|
||||
}
|
||||
], [
|
||||
1, function() {
|
||||
return write(Array(2049).join(' ') + 'h');
|
||||
}
|
||||
], [
|
||||
5, function() {
|
||||
return write('h');
|
||||
}
|
||||
], [
|
||||
25, function() {
|
||||
return write('h');
|
||||
}
|
||||
], [
|
||||
125, function() {
|
||||
return write('h');
|
||||
}
|
||||
], [
|
||||
625, function() {
|
||||
return write('h');
|
||||
}
|
||||
], [
|
||||
3125, function() {
|
||||
write('h');
|
||||
return res.end();
|
||||
}
|
||||
]
|
||||
]);
|
||||
return true;
|
||||
},
|
||||
info: function(req, res, _) {
|
||||
var info;
|
||||
info = {
|
||||
websocket: this.options.websocket,
|
||||
origins: ['*:*'],
|
||||
cookie_needed: !!this.options.jsessionid,
|
||||
entropy: utils.random32()
|
||||
};
|
||||
res.setHeader('Content-Type', 'application/json; charset=UTF-8');
|
||||
res.writeHead(200);
|
||||
return res.end(JSON.stringify(info));
|
||||
},
|
||||
info_options: function(req, res) {
|
||||
res.statusCode = 204;
|
||||
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, GET');
|
||||
res.setHeader('Access-Control-Max-Age', res.cache_for);
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
}).call(this);
|
29
node_modules/sockjs/lib/iframe.js
generated
vendored
Normal file
29
node_modules/sockjs/lib/iframe.js
generated
vendored
Normal file
@@ -0,0 +1,29 @@
|
||||
(function() {
|
||||
var iframe_template, utils;
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
iframe_template = "<!DOCTYPE html>\n<html>\n<head>\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n <script>\n document.domain = document.domain;\n _sockjs_onload = function(){SockJS.bootstrap_iframe();};\n </script>\n <script src=\"{{ sockjs_url }}\"></script>\n</head>\n<body>\n <h2>Don't panic!</h2>\n <p>This is a SockJS hidden iframe. It's used for cross domain magic.</p>\n</body>\n</html>";
|
||||
|
||||
exports.app = {
|
||||
iframe: function(req, res) {
|
||||
var content, context, k, quoted_md5;
|
||||
context = {
|
||||
'{{ sockjs_url }}': this.options.sockjs_url
|
||||
};
|
||||
content = iframe_template;
|
||||
for (k in context) {
|
||||
content = content.replace(k, context[k]);
|
||||
}
|
||||
quoted_md5 = '"' + utils.md5_hex(content) + '"';
|
||||
if ('if-none-match' in req.headers && req.headers['if-none-match'] === quoted_md5) {
|
||||
res.statusCode = 304;
|
||||
return '';
|
||||
}
|
||||
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
||||
res.setHeader('ETag', quoted_md5);
|
||||
return content;
|
||||
}
|
||||
};
|
||||
|
||||
}).call(this);
|
216
node_modules/sockjs/lib/sockjs.js
generated
vendored
Normal file
216
node_modules/sockjs/lib/sockjs.js
generated
vendored
Normal file
@@ -0,0 +1,216 @@
|
||||
(function() {
|
||||
var App, Listener, Server, chunking_test, events, fs, generate_dispatcher, iframe, sockjsVersion, trans_eventsource, trans_htmlfile, trans_jsonp, trans_websocket, trans_xhr, utils, webjs,
|
||||
__hasProp = Object.prototype.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; },
|
||||
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
|
||||
|
||||
events = require('events');
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
webjs = require('./webjs');
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
trans_websocket = require('./trans-websocket');
|
||||
|
||||
trans_jsonp = require('./trans-jsonp');
|
||||
|
||||
trans_xhr = require('./trans-xhr');
|
||||
|
||||
iframe = require('./iframe');
|
||||
|
||||
trans_eventsource = require('./trans-eventsource');
|
||||
|
||||
trans_htmlfile = require('./trans-htmlfile');
|
||||
|
||||
chunking_test = require('./chunking-test');
|
||||
|
||||
sockjsVersion = function() {
|
||||
var pkg;
|
||||
try {
|
||||
pkg = fs.readFileSync(__dirname + '/../package.json', 'utf-8');
|
||||
} catch (x) {
|
||||
|
||||
}
|
||||
if (pkg) {
|
||||
return JSON.parse(pkg).version;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
App = (function(_super) {
|
||||
|
||||
__extends(App, _super);
|
||||
|
||||
function App() {
|
||||
App.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
App.prototype.welcome_screen = function(req, res) {
|
||||
res.setHeader('content-type', 'text/plain; charset=UTF-8');
|
||||
res.writeHead(200);
|
||||
res.end("Welcome to SockJS!\n");
|
||||
return true;
|
||||
};
|
||||
|
||||
App.prototype.handle_404 = function(req, res) {
|
||||
res.setHeader('content-type', 'text/plain; charset=UTF-8');
|
||||
res.writeHead(404);
|
||||
res.end('404 Error: Page not found\n');
|
||||
return true;
|
||||
};
|
||||
|
||||
App.prototype.disabled_transport = function(req, res, data) {
|
||||
return this.handle_404(req, res, data);
|
||||
};
|
||||
|
||||
App.prototype.h_sid = function(req, res, data) {
|
||||
var jsid;
|
||||
req.cookies = utils.parseCookie(req.headers.cookie);
|
||||
if (typeof this.options.jsessionid === 'function') {
|
||||
this.options.jsessionid(req, res);
|
||||
} else if (this.options.jsessionid && res.setHeader) {
|
||||
jsid = req.cookies['JSESSIONID'] || 'dummy';
|
||||
res.setHeader('Set-Cookie', 'JSESSIONID=' + jsid + '; path=/');
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
App.prototype.log = function(severity, line) {
|
||||
return this.options.log(severity, line);
|
||||
};
|
||||
|
||||
return App;
|
||||
|
||||
})(webjs.GenericApp);
|
||||
|
||||
utils.objectExtend(App.prototype, iframe.app);
|
||||
|
||||
utils.objectExtend(App.prototype, chunking_test.app);
|
||||
|
||||
utils.objectExtend(App.prototype, trans_websocket.app);
|
||||
|
||||
utils.objectExtend(App.prototype, trans_jsonp.app);
|
||||
|
||||
utils.objectExtend(App.prototype, trans_xhr.app);
|
||||
|
||||
utils.objectExtend(App.prototype, trans_eventsource.app);
|
||||
|
||||
utils.objectExtend(App.prototype, trans_htmlfile.app);
|
||||
|
||||
generate_dispatcher = function(options) {
|
||||
var dispatcher, opts_filters, p, t,
|
||||
_this = this;
|
||||
p = function(s) {
|
||||
return new RegExp('^' + options.prefix + s + '[/]?$');
|
||||
};
|
||||
t = function(s) {
|
||||
return [p('/([^/.]+)/([^/.]+)' + s), 'server', 'session'];
|
||||
};
|
||||
opts_filters = function(options_filter) {
|
||||
if (options_filter == null) options_filter = 'xhr_options';
|
||||
return ['h_sid', 'xhr_cors', 'cache_for', options_filter, 'expose'];
|
||||
};
|
||||
dispatcher = [['GET', p(''), ['welcome_screen']], ['GET', p('/iframe[0-9-.a-z_]*.html'), ['iframe', 'cache_for', 'expose']], ['OPTIONS', p('/info'), opts_filters('info_options')], ['GET', p('/info'), ['xhr_cors', 'h_no_cache', 'info', 'expose']], ['OPTIONS', p('/chunking_test'), opts_filters()], ['POST', p('/chunking_test'), ['xhr_cors', 'expect_xhr', 'chunking_test']], ['GET', p('/websocket'), ['raw_websocket']], ['GET', t('/jsonp'), ['h_sid', 'h_no_cache', 'jsonp']], ['POST', t('/jsonp_send'), ['h_sid', 'h_no_cache', 'expect_form', 'jsonp_send']], ['POST', t('/xhr'), ['h_sid', 'h_no_cache', 'xhr_cors', 'xhr_poll']], ['OPTIONS', t('/xhr'), opts_filters()], ['POST', t('/xhr_send'), ['h_sid', 'h_no_cache', 'xhr_cors', 'expect_xhr', 'xhr_send']], ['OPTIONS', t('/xhr_send'), opts_filters()], ['POST', t('/xhr_streaming'), ['h_sid', 'h_no_cache', 'xhr_cors', 'xhr_streaming']], ['OPTIONS', t('/xhr_streaming'), opts_filters()], ['GET', t('/eventsource'), ['h_sid', 'h_no_cache', 'eventsource']], ['GET', t('/htmlfile'), ['h_sid', 'h_no_cache', 'htmlfile']]];
|
||||
if (options.websocket) {
|
||||
dispatcher.push(['GET', t('/websocket'), ['sockjs_websocket']]);
|
||||
} else {
|
||||
dispatcher.push(['GET', t('/websocket'), ['cache_for', 'disabled_transport']]);
|
||||
}
|
||||
return dispatcher;
|
||||
};
|
||||
|
||||
Listener = (function() {
|
||||
|
||||
function Listener(options, emit) {
|
||||
this.options = options;
|
||||
this.handler = __bind(this.handler, this);
|
||||
this.app = new App();
|
||||
this.app.options = options;
|
||||
this.app.emit = emit;
|
||||
this.app.log('debug', 'SockJS v' + sockjsVersion() + ' ' + 'bound to ' + JSON.stringify(options.prefix));
|
||||
this.dispatcher = generate_dispatcher(this.options);
|
||||
this.webjs_handler = webjs.generateHandler(this.app, this.dispatcher);
|
||||
this.path_regexp = new RegExp('^' + this.options.prefix + '([/].+|[/]?)$');
|
||||
}
|
||||
|
||||
Listener.prototype.handler = function(req, res, extra) {
|
||||
if (!req.url.match(this.path_regexp)) return false;
|
||||
this.webjs_handler(req, res, extra);
|
||||
return true;
|
||||
};
|
||||
|
||||
Listener.prototype.getHandler = function() {
|
||||
var _this = this;
|
||||
return function(a, b, c) {
|
||||
return _this.handler(a, b, c);
|
||||
};
|
||||
};
|
||||
|
||||
return Listener;
|
||||
|
||||
})();
|
||||
|
||||
Server = (function(_super) {
|
||||
|
||||
__extends(Server, _super);
|
||||
|
||||
function Server(user_options) {
|
||||
this.options = {
|
||||
prefix: '',
|
||||
response_limit: 128 * 1024,
|
||||
websocket: true,
|
||||
jsessionid: false,
|
||||
heartbeat_delay: 25000,
|
||||
disconnect_delay: 5000,
|
||||
log: function(severity, line) {
|
||||
return console.log(line);
|
||||
},
|
||||
sockjs_url: 'https://d1fxtkz8shb9d2.cloudfront.net/sockjs-0.3.min.js'
|
||||
};
|
||||
if (user_options) utils.objectExtend(this.options, user_options);
|
||||
}
|
||||
|
||||
Server.prototype.listener = function(handler_options) {
|
||||
var options,
|
||||
_this = this;
|
||||
options = utils.objectExtend({}, this.options);
|
||||
if (handler_options) utils.objectExtend(options, handler_options);
|
||||
return new Listener(options, function() {
|
||||
return _this.emit.apply(_this, arguments);
|
||||
});
|
||||
};
|
||||
|
||||
Server.prototype.installHandlers = function(http_server, handler_options) {
|
||||
var handler;
|
||||
handler = this.listener(handler_options).getHandler();
|
||||
utils.overshadowListeners(http_server, 'request', handler);
|
||||
utils.overshadowListeners(http_server, 'upgrade', handler);
|
||||
return true;
|
||||
};
|
||||
|
||||
Server.prototype.middleware = function(handler_options) {
|
||||
var handler;
|
||||
handler = this.listener(handler_options).getHandler();
|
||||
handler.upgrade = handler;
|
||||
return handler;
|
||||
};
|
||||
|
||||
return Server;
|
||||
|
||||
})(events.EventEmitter);
|
||||
|
||||
exports.createServer = function(options) {
|
||||
return new Server(options);
|
||||
};
|
||||
|
||||
exports.listen = function(http_server, options) {
|
||||
var srv;
|
||||
srv = exports.createServer(options);
|
||||
if (http_server) srv.installHandlers(http_server);
|
||||
return srv;
|
||||
};
|
||||
|
||||
}).call(this);
|
40
node_modules/sockjs/lib/trans-eventsource.js
generated
vendored
Normal file
40
node_modules/sockjs/lib/trans-eventsource.js
generated
vendored
Normal file
@@ -0,0 +1,40 @@
|
||||
(function() {
|
||||
var EventSourceReceiver, transport, utils,
|
||||
__hasProp = Object.prototype.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
transport = require('./transport');
|
||||
|
||||
EventSourceReceiver = (function(_super) {
|
||||
|
||||
__extends(EventSourceReceiver, _super);
|
||||
|
||||
function EventSourceReceiver() {
|
||||
EventSourceReceiver.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
EventSourceReceiver.prototype.protocol = "eventsource";
|
||||
|
||||
EventSourceReceiver.prototype.doSendFrame = function(payload) {
|
||||
var data;
|
||||
data = ['data: ', utils.escape_selected(payload, '\r\n\x00'), '\r\n\r\n'];
|
||||
return EventSourceReceiver.__super__.doSendFrame.call(this, data.join(''));
|
||||
};
|
||||
|
||||
return EventSourceReceiver;
|
||||
|
||||
})(transport.ResponseReceiver);
|
||||
|
||||
exports.app = {
|
||||
eventsource: function(req, res) {
|
||||
res.setHeader('Content-Type', 'text/event-stream; charset=UTF-8');
|
||||
res.writeHead(200);
|
||||
res.write('\r\n');
|
||||
transport.register(req, this, new EventSourceReceiver(req, res, this.options));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
}).call(this);
|
58
node_modules/sockjs/lib/trans-htmlfile.js
generated
vendored
Normal file
58
node_modules/sockjs/lib/trans-htmlfile.js
generated
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
(function() {
|
||||
var HtmlFileReceiver, iframe_template, transport, utils,
|
||||
__hasProp = Object.prototype.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
transport = require('./transport');
|
||||
|
||||
iframe_template = "<!doctype html>\n<html><head>\n <meta http-equiv=\"X-UA-Compatible\" content=\"IE=edge\" />\n <meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\" />\n</head><body><h2>Don't panic!</h2>\n <script>\n document.domain = document.domain;\n var c = parent.{{ callback }};\n c.start();\n function p(d) {c.message(d);};\n window.onload = function() {c.stop();};\n </script>";
|
||||
|
||||
iframe_template += Array(1024 - iframe_template.length + 14).join(' ');
|
||||
|
||||
iframe_template += '\r\n\r\n';
|
||||
|
||||
HtmlFileReceiver = (function(_super) {
|
||||
|
||||
__extends(HtmlFileReceiver, _super);
|
||||
|
||||
function HtmlFileReceiver() {
|
||||
HtmlFileReceiver.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
HtmlFileReceiver.prototype.protocol = "htmlfile";
|
||||
|
||||
HtmlFileReceiver.prototype.doSendFrame = function(payload) {
|
||||
return HtmlFileReceiver.__super__.doSendFrame.call(this, '<script>\np(' + JSON.stringify(payload) + ');\n</script>\r\n');
|
||||
};
|
||||
|
||||
return HtmlFileReceiver;
|
||||
|
||||
})(transport.ResponseReceiver);
|
||||
|
||||
exports.app = {
|
||||
htmlfile: function(req, res) {
|
||||
var callback;
|
||||
if (!('c' in req.query || 'callback' in req.query)) {
|
||||
throw {
|
||||
status: 500,
|
||||
message: '"callback" parameter required'
|
||||
};
|
||||
}
|
||||
callback = 'c' in req.query ? req.query['c'] : req.query['callback'];
|
||||
if (/[^a-zA-Z0-9-_.]/.test(callback)) {
|
||||
throw {
|
||||
status: 500,
|
||||
message: 'invalid "callback" parameter'
|
||||
};
|
||||
}
|
||||
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
||||
res.writeHead(200);
|
||||
res.write(iframe_template.replace(/{{ callback }}/g, callback));
|
||||
transport.register(req, this, new HtmlFileReceiver(req, res, this.options));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
}).call(this);
|
104
node_modules/sockjs/lib/trans-jsonp.js
generated
vendored
Normal file
104
node_modules/sockjs/lib/trans-jsonp.js
generated
vendored
Normal file
@@ -0,0 +1,104 @@
|
||||
(function() {
|
||||
var JsonpReceiver, transport,
|
||||
__hasProp = Object.prototype.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
|
||||
|
||||
transport = require('./transport');
|
||||
|
||||
JsonpReceiver = (function(_super) {
|
||||
|
||||
__extends(JsonpReceiver, _super);
|
||||
|
||||
JsonpReceiver.prototype.protocol = "jsonp-polling";
|
||||
|
||||
JsonpReceiver.prototype.max_response_size = 1;
|
||||
|
||||
function JsonpReceiver(req, res, options, callback) {
|
||||
this.callback = callback;
|
||||
JsonpReceiver.__super__.constructor.call(this, req, res, options);
|
||||
}
|
||||
|
||||
JsonpReceiver.prototype.doSendFrame = function(payload) {
|
||||
return JsonpReceiver.__super__.doSendFrame.call(this, this.callback + "(" + JSON.stringify(payload) + ");\r\n");
|
||||
};
|
||||
|
||||
return JsonpReceiver;
|
||||
|
||||
})(transport.ResponseReceiver);
|
||||
|
||||
exports.app = {
|
||||
jsonp: function(req, res, _, next_filter) {
|
||||
var callback;
|
||||
if (!('c' in req.query || 'callback' in req.query)) {
|
||||
throw {
|
||||
status: 500,
|
||||
message: '"callback" parameter required'
|
||||
};
|
||||
}
|
||||
callback = 'c' in req.query ? req.query['c'] : req.query['callback'];
|
||||
if (/[^a-zA-Z0-9-_.]/.test(callback)) {
|
||||
throw {
|
||||
status: 500,
|
||||
message: 'invalid "callback" parameter'
|
||||
};
|
||||
}
|
||||
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
|
||||
res.writeHead(200);
|
||||
transport.register(req, this, new JsonpReceiver(req, res, this.options, callback));
|
||||
return true;
|
||||
},
|
||||
jsonp_send: function(req, res, query) {
|
||||
var d, jsonp, message, _i, _len;
|
||||
if (!query) {
|
||||
throw {
|
||||
status: 500,
|
||||
message: 'Payload expected.'
|
||||
};
|
||||
}
|
||||
if (typeof query === 'string') {
|
||||
try {
|
||||
d = JSON.parse(query);
|
||||
} catch (x) {
|
||||
throw {
|
||||
status: 500,
|
||||
message: 'Broken JSON encoding.'
|
||||
};
|
||||
}
|
||||
} else {
|
||||
d = query.d;
|
||||
}
|
||||
if (typeof d === 'string' && d) {
|
||||
try {
|
||||
d = JSON.parse(d);
|
||||
} catch (x) {
|
||||
throw {
|
||||
status: 500,
|
||||
message: 'Broken JSON encoding.'
|
||||
};
|
||||
}
|
||||
}
|
||||
if (!d || d.__proto__.constructor !== Array) {
|
||||
throw {
|
||||
status: 500,
|
||||
message: 'Payload expected.'
|
||||
};
|
||||
}
|
||||
jsonp = transport.Session.bySessionId(req.session);
|
||||
if (jsonp === null) {
|
||||
throw {
|
||||
status: 404
|
||||
};
|
||||
}
|
||||
for (_i = 0, _len = d.length; _i < _len; _i++) {
|
||||
message = d[_i];
|
||||
jsonp.didMessage(message);
|
||||
}
|
||||
res.setHeader('Content-Length', '2');
|
||||
res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
|
||||
res.writeHead(200);
|
||||
res.end('ok');
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
}).call(this);
|
205
node_modules/sockjs/lib/trans-websocket.js
generated
vendored
Normal file
205
node_modules/sockjs/lib/trans-websocket.js
generated
vendored
Normal file
@@ -0,0 +1,205 @@
|
||||
(function() {
|
||||
var FayeWebsocket, RawWebsocketSessionReceiver, Transport, WebSocketReceiver, transport, utils,
|
||||
__hasProp = Object.prototype.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
|
||||
|
||||
FayeWebsocket = require('faye-websocket');
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
transport = require('./transport');
|
||||
|
||||
exports.app = {
|
||||
_websocket_check: function(req, connection, head) {
|
||||
var conn;
|
||||
if ((req.headers.upgrade || '').toLowerCase() !== 'websocket') {
|
||||
throw {
|
||||
status: 400,
|
||||
message: 'Can "Upgrade" only to "WebSocket".'
|
||||
};
|
||||
}
|
||||
conn = (req.headers.connection || '').toLowerCase();
|
||||
if ((conn.split(/, */)).indexOf('upgrade') === -1) {
|
||||
throw {
|
||||
status: 400,
|
||||
message: '"Connection" must be "Upgrade".'
|
||||
};
|
||||
}
|
||||
},
|
||||
sockjs_websocket: function(req, connection, head) {
|
||||
var ws,
|
||||
_this = this;
|
||||
this._websocket_check(req, connection, head);
|
||||
ws = new FayeWebsocket(req, connection, head);
|
||||
ws.onopen = function() {
|
||||
return transport.registerNoSession(req, _this, new WebSocketReceiver(ws, connection));
|
||||
};
|
||||
return true;
|
||||
},
|
||||
raw_websocket: function(req, connection, head) {
|
||||
var ver, ws,
|
||||
_this = this;
|
||||
this._websocket_check(req, connection, head);
|
||||
ver = req.headers['sec-websocket-version'] || '';
|
||||
if (['8', '13'].indexOf(ver) === -1) {
|
||||
throw {
|
||||
status: 400,
|
||||
message: 'Only supported WebSocket protocol is RFC 6455.'
|
||||
};
|
||||
}
|
||||
ws = new FayeWebsocket(req, connection, head);
|
||||
ws.onopen = function() {
|
||||
return new RawWebsocketSessionReceiver(req, connection, _this, ws);
|
||||
};
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
WebSocketReceiver = (function(_super) {
|
||||
|
||||
__extends(WebSocketReceiver, _super);
|
||||
|
||||
WebSocketReceiver.prototype.protocol = "websocket";
|
||||
|
||||
function WebSocketReceiver(ws, connection) {
|
||||
var _this = this;
|
||||
this.ws = ws;
|
||||
this.connection = connection;
|
||||
try {
|
||||
this.connection.setKeepAlive(true, 5000);
|
||||
this.connection.setNoDelay(true);
|
||||
} catch (x) {
|
||||
|
||||
}
|
||||
this.ws.addEventListener('message', function(m) {
|
||||
return _this.didMessage(m.data);
|
||||
});
|
||||
WebSocketReceiver.__super__.constructor.call(this, this.connection);
|
||||
}
|
||||
|
||||
WebSocketReceiver.prototype.setUp = function() {
|
||||
WebSocketReceiver.__super__.setUp.apply(this, arguments);
|
||||
return this.ws.addEventListener('close', this.thingy_end_cb);
|
||||
};
|
||||
|
||||
WebSocketReceiver.prototype.tearDown = function() {
|
||||
this.ws.removeEventListener('close', this.thingy_end_cb);
|
||||
return WebSocketReceiver.__super__.tearDown.apply(this, arguments);
|
||||
};
|
||||
|
||||
WebSocketReceiver.prototype.didMessage = function(payload) {
|
||||
var message, msg, _i, _len, _results;
|
||||
if (this.ws && this.session && payload.length > 0) {
|
||||
try {
|
||||
message = JSON.parse(payload);
|
||||
} catch (x) {
|
||||
return this.didClose(1002, 'Broken framing.');
|
||||
}
|
||||
if (payload[0] === '[') {
|
||||
_results = [];
|
||||
for (_i = 0, _len = message.length; _i < _len; _i++) {
|
||||
msg = message[_i];
|
||||
_results.push(this.session.didMessage(msg));
|
||||
}
|
||||
return _results;
|
||||
} else {
|
||||
return this.session.didMessage(message);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
WebSocketReceiver.prototype.doSendFrame = function(payload) {
|
||||
if (this.ws) {
|
||||
try {
|
||||
this.ws.send(payload);
|
||||
return true;
|
||||
} catch (x) {
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
WebSocketReceiver.prototype.didClose = function() {
|
||||
WebSocketReceiver.__super__.didClose.apply(this, arguments);
|
||||
try {
|
||||
this.ws.close(1000, "Normal closure", false);
|
||||
} catch (x) {
|
||||
|
||||
}
|
||||
this.ws = null;
|
||||
return this.connection = null;
|
||||
};
|
||||
|
||||
return WebSocketReceiver;
|
||||
|
||||
})(transport.GenericReceiver);
|
||||
|
||||
Transport = transport.Transport;
|
||||
|
||||
RawWebsocketSessionReceiver = (function(_super) {
|
||||
|
||||
__extends(RawWebsocketSessionReceiver, _super);
|
||||
|
||||
function RawWebsocketSessionReceiver(req, conn, server, ws) {
|
||||
var _this = this;
|
||||
this.ws = ws;
|
||||
this.prefix = server.options.prefix;
|
||||
this.readyState = Transport.OPEN;
|
||||
this.recv = {
|
||||
connection: conn,
|
||||
protocol: "websocket-raw"
|
||||
};
|
||||
this.connection = new transport.SockJSConnection(this);
|
||||
this.decorateConnection(req);
|
||||
server.emit('connection', this.connection);
|
||||
this._end_cb = function() {
|
||||
return _this.didClose();
|
||||
};
|
||||
this.ws.addEventListener('close', this._end_cb);
|
||||
this._message_cb = function(m) {
|
||||
return _this.didMessage(m);
|
||||
};
|
||||
this.ws.addEventListener('message', this._message_cb);
|
||||
}
|
||||
|
||||
RawWebsocketSessionReceiver.prototype.didMessage = function(m) {
|
||||
if (this.readyState === Transport.OPEN) this.connection.emit('data', m.data);
|
||||
};
|
||||
|
||||
RawWebsocketSessionReceiver.prototype.send = function(payload) {
|
||||
if (this.readyState !== Transport.OPEN) return false;
|
||||
this.ws.send(payload);
|
||||
return true;
|
||||
};
|
||||
|
||||
RawWebsocketSessionReceiver.prototype.close = function(status, reason) {
|
||||
if (status == null) status = 1000;
|
||||
if (reason == null) reason = "Normal closure";
|
||||
if (this.readyState !== Transport.OPEN) return false;
|
||||
this.readyState = Transport.CLOSING;
|
||||
this.ws.close(status, reason, false);
|
||||
return true;
|
||||
};
|
||||
|
||||
RawWebsocketSessionReceiver.prototype.didClose = function() {
|
||||
if (!this.ws) return;
|
||||
this.ws.removeEventListener('message', this._message_cb);
|
||||
this.ws.removeEventListener('close', this._end_cb);
|
||||
try {
|
||||
this.ws.close(1000, "Normal closure", false);
|
||||
} catch (x) {
|
||||
|
||||
}
|
||||
this.ws = null;
|
||||
this.readyState = Transport.CLOSED;
|
||||
this.connection.emit('end');
|
||||
this.connection.emit('close');
|
||||
return this.connection = null;
|
||||
};
|
||||
|
||||
return RawWebsocketSessionReceiver;
|
||||
|
||||
})(transport.Session);
|
||||
|
||||
}).call(this);
|
116
node_modules/sockjs/lib/trans-xhr.js
generated
vendored
Normal file
116
node_modules/sockjs/lib/trans-xhr.js
generated
vendored
Normal file
@@ -0,0 +1,116 @@
|
||||
(function() {
|
||||
var XhrPollingReceiver, XhrStreamingReceiver, transport, utils,
|
||||
__hasProp = Object.prototype.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
|
||||
|
||||
transport = require('./transport');
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
XhrStreamingReceiver = (function(_super) {
|
||||
|
||||
__extends(XhrStreamingReceiver, _super);
|
||||
|
||||
function XhrStreamingReceiver() {
|
||||
XhrStreamingReceiver.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
XhrStreamingReceiver.prototype.protocol = "xhr-streaming";
|
||||
|
||||
XhrStreamingReceiver.prototype.doSendFrame = function(payload) {
|
||||
return XhrStreamingReceiver.__super__.doSendFrame.call(this, payload + '\n');
|
||||
};
|
||||
|
||||
return XhrStreamingReceiver;
|
||||
|
||||
})(transport.ResponseReceiver);
|
||||
|
||||
XhrPollingReceiver = (function(_super) {
|
||||
|
||||
__extends(XhrPollingReceiver, _super);
|
||||
|
||||
function XhrPollingReceiver() {
|
||||
XhrPollingReceiver.__super__.constructor.apply(this, arguments);
|
||||
}
|
||||
|
||||
XhrPollingReceiver.prototype.protocol = "xhr-polling";
|
||||
|
||||
XhrPollingReceiver.prototype.max_response_size = 1;
|
||||
|
||||
return XhrPollingReceiver;
|
||||
|
||||
})(XhrStreamingReceiver);
|
||||
|
||||
exports.app = {
|
||||
xhr_options: function(req, res) {
|
||||
res.statusCode = 204;
|
||||
res.setHeader('Access-Control-Allow-Methods', 'OPTIONS, POST');
|
||||
res.setHeader('Access-Control-Max-Age', res.cache_for);
|
||||
return '';
|
||||
},
|
||||
xhr_send: function(req, res, data) {
|
||||
var d, jsonp, message, _i, _len;
|
||||
if (!data) {
|
||||
throw {
|
||||
status: 500,
|
||||
message: 'Payload expected.'
|
||||
};
|
||||
}
|
||||
try {
|
||||
d = JSON.parse(data);
|
||||
} catch (x) {
|
||||
throw {
|
||||
status: 500,
|
||||
message: 'Broken JSON encoding.'
|
||||
};
|
||||
}
|
||||
if (!d || d.__proto__.constructor !== Array) {
|
||||
throw {
|
||||
status: 500,
|
||||
message: 'Payload expected.'
|
||||
};
|
||||
}
|
||||
jsonp = transport.Session.bySessionId(req.session);
|
||||
if (!jsonp) {
|
||||
throw {
|
||||
status: 404
|
||||
};
|
||||
}
|
||||
for (_i = 0, _len = d.length; _i < _len; _i++) {
|
||||
message = d[_i];
|
||||
jsonp.didMessage(message);
|
||||
}
|
||||
res.setHeader('Content-Type', 'text/plain; charset=UTF-8');
|
||||
res.writeHead(204);
|
||||
res.end();
|
||||
return true;
|
||||
},
|
||||
xhr_cors: function(req, res, content) {
|
||||
var headers, origin;
|
||||
if (!req.headers['origin'] || req.headers['origin'] === 'null') {
|
||||
origin = '*';
|
||||
} else {
|
||||
origin = req.headers['origin'];
|
||||
}
|
||||
res.setHeader('Access-Control-Allow-Origin', origin);
|
||||
headers = req.headers['access-control-request-headers'];
|
||||
if (headers) res.setHeader('Access-Control-Allow-Headers', headers);
|
||||
res.setHeader('Access-Control-Allow-Credentials', 'true');
|
||||
return content;
|
||||
},
|
||||
xhr_poll: function(req, res, _, next_filter) {
|
||||
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
|
||||
res.writeHead(200);
|
||||
transport.register(req, this, new XhrPollingReceiver(req, res, this.options));
|
||||
return true;
|
||||
},
|
||||
xhr_streaming: function(req, res, _, next_filter) {
|
||||
res.setHeader('Content-Type', 'application/javascript; charset=UTF-8');
|
||||
res.writeHead(200);
|
||||
res.write(Array(2049).join('h') + '\n');
|
||||
transport.register(req, this, new XhrStreamingReceiver(req, res, this.options));
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
}).call(this);
|
386
node_modules/sockjs/lib/transport.js
generated
vendored
Normal file
386
node_modules/sockjs/lib/transport.js
generated
vendored
Normal file
@@ -0,0 +1,386 @@
|
||||
(function() {
|
||||
var GenericReceiver, MAP, ResponseReceiver, Session, SockJSConnection, Transport, closeFrame, register, stream, utils, uuid,
|
||||
__hasProp = Object.prototype.hasOwnProperty,
|
||||
__extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; };
|
||||
|
||||
stream = require('stream');
|
||||
|
||||
uuid = require('node-uuid');
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
Transport = (function() {
|
||||
|
||||
function Transport() {}
|
||||
|
||||
return Transport;
|
||||
|
||||
})();
|
||||
|
||||
Transport.CONNECTING = 0;
|
||||
|
||||
Transport.OPEN = 1;
|
||||
|
||||
Transport.CLOSING = 2;
|
||||
|
||||
Transport.CLOSED = 3;
|
||||
|
||||
closeFrame = function(status, reason) {
|
||||
return 'c' + JSON.stringify([status, reason]);
|
||||
};
|
||||
|
||||
SockJSConnection = (function(_super) {
|
||||
|
||||
__extends(SockJSConnection, _super);
|
||||
|
||||
function SockJSConnection(_session) {
|
||||
this._session = _session;
|
||||
this.id = uuid();
|
||||
this.headers = {};
|
||||
this.prefix = this._session.prefix;
|
||||
}
|
||||
|
||||
SockJSConnection.prototype.toString = function() {
|
||||
return '<SockJSConnection ' + this.id + '>';
|
||||
};
|
||||
|
||||
SockJSConnection.prototype.write = function(string) {
|
||||
return this._session.send('' + string);
|
||||
};
|
||||
|
||||
SockJSConnection.prototype.end = function(string) {
|
||||
if (string) this.write(string);
|
||||
this.close();
|
||||
return null;
|
||||
};
|
||||
|
||||
SockJSConnection.prototype.close = function(code, reason) {
|
||||
return this._session.close(code, reason);
|
||||
};
|
||||
|
||||
SockJSConnection.prototype.destroy = function() {
|
||||
this.removeAllListeners();
|
||||
return this.end();
|
||||
};
|
||||
|
||||
SockJSConnection.prototype.destroySoon = function() {
|
||||
return this.destroy();
|
||||
};
|
||||
|
||||
return SockJSConnection;
|
||||
|
||||
})(stream.Stream);
|
||||
|
||||
SockJSConnection.prototype.__defineGetter__('readable', function() {
|
||||
return this._session.readyState === Transport.OPEN;
|
||||
});
|
||||
|
||||
SockJSConnection.prototype.__defineGetter__('writable', function() {
|
||||
return this._session.readyState === Transport.OPEN;
|
||||
});
|
||||
|
||||
SockJSConnection.prototype.__defineGetter__('readyState', function() {
|
||||
return this._session.readyState;
|
||||
});
|
||||
|
||||
MAP = {};
|
||||
|
||||
Session = (function() {
|
||||
|
||||
function Session(session_id, server) {
|
||||
var _this = this;
|
||||
this.session_id = session_id;
|
||||
this.heartbeat_delay = server.options.heartbeat_delay;
|
||||
this.disconnect_delay = server.options.disconnect_delay;
|
||||
this.prefix = server.options.prefix;
|
||||
this.send_buffer = [];
|
||||
this.is_closing = false;
|
||||
this.readyState = Transport.CONNECTING;
|
||||
if (this.session_id) MAP[this.session_id] = this;
|
||||
this.timeout_cb = function() {
|
||||
return _this.didTimeout();
|
||||
};
|
||||
this.to_tref = setTimeout(this.timeout_cb, this.disconnect_delay);
|
||||
this.connection = new SockJSConnection(this);
|
||||
this.emit_open = function() {
|
||||
_this.emit_open = null;
|
||||
return server.emit('connection', _this.connection);
|
||||
};
|
||||
}
|
||||
|
||||
Session.prototype.register = function(req, recv) {
|
||||
if (this.recv) {
|
||||
recv.doSendFrame(closeFrame(2010, "Another connection still open"));
|
||||
recv.didClose();
|
||||
return;
|
||||
}
|
||||
if (this.to_tref) {
|
||||
clearTimeout(this.to_tref);
|
||||
this.to_tref = null;
|
||||
}
|
||||
if (this.readyState === Transport.CLOSING) {
|
||||
this.flushToRecv(recv);
|
||||
recv.doSendFrame(this.close_frame);
|
||||
recv.didClose();
|
||||
this.to_tref = setTimeout(this.timeout_cb, this.disconnect_delay);
|
||||
return;
|
||||
}
|
||||
this.recv = recv;
|
||||
this.recv.session = this;
|
||||
this.decorateConnection(req);
|
||||
if (this.readyState === Transport.CONNECTING) {
|
||||
this.recv.doSendFrame('o');
|
||||
this.readyState = Transport.OPEN;
|
||||
process.nextTick(this.emit_open);
|
||||
}
|
||||
if (!this.recv) return;
|
||||
this.tryFlush();
|
||||
};
|
||||
|
||||
Session.prototype.decorateConnection = function(req) {
|
||||
var address, headers, key, remoteAddress, remotePort, socket, _i, _len, _ref;
|
||||
if (!(socket = this.recv.connection)) socket = this.recv.response.connection;
|
||||
try {
|
||||
remoteAddress = socket.remoteAddress;
|
||||
remotePort = socket.remotePort;
|
||||
address = socket.address();
|
||||
} catch (x) {
|
||||
|
||||
}
|
||||
if (remoteAddress) {
|
||||
this.connection.remoteAddress = remoteAddress;
|
||||
this.connection.remotePort = remotePort;
|
||||
this.connection.address = address;
|
||||
}
|
||||
this.connection.url = req.url;
|
||||
this.connection.pathname = req.pathname;
|
||||
this.connection.protocol = this.recv.protocol;
|
||||
headers = {};
|
||||
_ref = ['referer', 'x-client-ip', 'x-forwarded-for', 'x-cluster-client-ip', 'via', 'x-real-ip', 'host', 'user-agent', 'accept-language'];
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
key = _ref[_i];
|
||||
if (req.headers[key]) headers[key] = req.headers[key];
|
||||
}
|
||||
if (headers) return this.connection.headers = headers;
|
||||
};
|
||||
|
||||
Session.prototype.unregister = function() {
|
||||
this.recv.session = null;
|
||||
this.recv = null;
|
||||
if (this.to_tref) clearTimeout(this.to_tref);
|
||||
return this.to_tref = setTimeout(this.timeout_cb, this.disconnect_delay);
|
||||
};
|
||||
|
||||
Session.prototype.flushToRecv = function(recv) {
|
||||
var sb, _ref;
|
||||
if (this.send_buffer.length > 0) {
|
||||
_ref = [this.send_buffer, []], sb = _ref[0], this.send_buffer = _ref[1];
|
||||
recv.doSendBulk(sb);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
Session.prototype.tryFlush = function() {
|
||||
var x,
|
||||
_this = this;
|
||||
if (!this.flushToRecv(this.recv)) {
|
||||
if (this.to_tref) clearTimeout(this.to_tref);
|
||||
x = function() {
|
||||
if (_this.recv) {
|
||||
_this.to_tref = setTimeout(x, _this.heartbeat_delay);
|
||||
return _this.recv.doSendFrame("h");
|
||||
}
|
||||
};
|
||||
this.to_tref = setTimeout(x, this.heartbeat_delay);
|
||||
}
|
||||
};
|
||||
|
||||
Session.prototype.didTimeout = function() {
|
||||
if (this.to_tref) {
|
||||
clearTimeout(this.to_tref);
|
||||
this.to_tref = null;
|
||||
}
|
||||
if (this.readyState !== Transport.CONNECTING && this.readyState !== Transport.OPEN && this.readyState !== Transport.CLOSING) {
|
||||
throw Error('INVALID_STATE_ERR');
|
||||
}
|
||||
if (this.recv) throw Error('RECV_STILL_THERE');
|
||||
this.readyState = Transport.CLOSED;
|
||||
this.connection.emit('end');
|
||||
this.connection.emit('close');
|
||||
this.connection = null;
|
||||
if (this.session_id) {
|
||||
delete MAP[this.session_id];
|
||||
return this.session_id = null;
|
||||
}
|
||||
};
|
||||
|
||||
Session.prototype.didMessage = function(payload) {
|
||||
if (this.readyState === Transport.OPEN) {
|
||||
this.connection.emit('data', payload);
|
||||
}
|
||||
};
|
||||
|
||||
Session.prototype.send = function(payload) {
|
||||
if (this.readyState !== Transport.OPEN) return false;
|
||||
this.send_buffer.push('' + payload);
|
||||
if (this.recv) this.tryFlush();
|
||||
return true;
|
||||
};
|
||||
|
||||
Session.prototype.close = function(status, reason) {
|
||||
if (status == null) status = 1000;
|
||||
if (reason == null) reason = "Normal closure";
|
||||
if (this.readyState !== Transport.OPEN) return false;
|
||||
this.readyState = Transport.CLOSING;
|
||||
this.close_frame = closeFrame(status, reason);
|
||||
if (this.recv) {
|
||||
this.recv.doSendFrame(this.close_frame);
|
||||
if (this.recv) this.recv.didClose();
|
||||
if (this.recv) this.unregister();
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
return Session;
|
||||
|
||||
})();
|
||||
|
||||
Session.bySessionId = function(session_id) {
|
||||
return MAP[session_id] || null;
|
||||
};
|
||||
|
||||
register = function(req, server, session_id, receiver) {
|
||||
var session;
|
||||
session = Session.bySessionId(session_id);
|
||||
if (!session) session = new Session(session_id, server);
|
||||
session.register(req, receiver);
|
||||
return session;
|
||||
};
|
||||
|
||||
exports.register = function(req, server, receiver) {
|
||||
return register(req, server, req.session, receiver);
|
||||
};
|
||||
|
||||
exports.registerNoSession = function(req, server, receiver) {
|
||||
return register(req, server, void 0, receiver);
|
||||
};
|
||||
|
||||
GenericReceiver = (function() {
|
||||
|
||||
function GenericReceiver(thingy) {
|
||||
this.thingy = thingy;
|
||||
this.setUp(this.thingy);
|
||||
}
|
||||
|
||||
GenericReceiver.prototype.setUp = function() {
|
||||
var _this = this;
|
||||
this.thingy_end_cb = function() {
|
||||
return _this.didAbort(1006, "Connection closed");
|
||||
};
|
||||
this.thingy.addListener('close', this.thingy_end_cb);
|
||||
return this.thingy.addListener('end', this.thingy_end_cb);
|
||||
};
|
||||
|
||||
GenericReceiver.prototype.tearDown = function() {
|
||||
this.thingy.removeListener('close', this.thingy_end_cb);
|
||||
this.thingy.removeListener('end', this.thingy_end_cb);
|
||||
return this.thingy_end_cb = null;
|
||||
};
|
||||
|
||||
GenericReceiver.prototype.didAbort = function(status, reason) {
|
||||
var session;
|
||||
session = this.session;
|
||||
this.didClose(status, reason);
|
||||
if (session) return session.didTimeout();
|
||||
};
|
||||
|
||||
GenericReceiver.prototype.didClose = function(status, reason) {
|
||||
if (this.thingy) {
|
||||
this.tearDown(this.thingy);
|
||||
this.thingy = null;
|
||||
}
|
||||
if (this.session) return this.session.unregister(status, reason);
|
||||
};
|
||||
|
||||
GenericReceiver.prototype.doSendBulk = function(messages) {
|
||||
var m, q_msgs;
|
||||
q_msgs = (function() {
|
||||
var _i, _len, _results;
|
||||
_results = [];
|
||||
for (_i = 0, _len = messages.length; _i < _len; _i++) {
|
||||
m = messages[_i];
|
||||
_results.push(utils.quote(m));
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
return this.doSendFrame('a' + '[' + q_msgs.join(',') + ']');
|
||||
};
|
||||
|
||||
return GenericReceiver;
|
||||
|
||||
})();
|
||||
|
||||
ResponseReceiver = (function(_super) {
|
||||
|
||||
__extends(ResponseReceiver, _super);
|
||||
|
||||
ResponseReceiver.prototype.max_response_size = void 0;
|
||||
|
||||
function ResponseReceiver(request, response, options) {
|
||||
this.request = request;
|
||||
this.response = response;
|
||||
this.options = options;
|
||||
this.curr_response_size = 0;
|
||||
try {
|
||||
this.request.connection.setKeepAlive(true, 5000);
|
||||
} catch (x) {
|
||||
|
||||
}
|
||||
ResponseReceiver.__super__.constructor.call(this, this.request.connection);
|
||||
if (this.max_response_size === void 0) {
|
||||
this.max_response_size = this.options.response_limit;
|
||||
}
|
||||
}
|
||||
|
||||
ResponseReceiver.prototype.doSendFrame = function(payload) {
|
||||
var r;
|
||||
this.curr_response_size += payload.length;
|
||||
r = false;
|
||||
try {
|
||||
this.response.write(payload);
|
||||
r = true;
|
||||
} catch (x) {
|
||||
|
||||
}
|
||||
if (this.max_response_size && this.curr_response_size >= this.max_response_size) {
|
||||
this.didClose();
|
||||
}
|
||||
return r;
|
||||
};
|
||||
|
||||
ResponseReceiver.prototype.didClose = function() {
|
||||
ResponseReceiver.__super__.didClose.apply(this, arguments);
|
||||
try {
|
||||
this.response.end();
|
||||
} catch (x) {
|
||||
|
||||
}
|
||||
return this.response = null;
|
||||
};
|
||||
|
||||
return ResponseReceiver;
|
||||
|
||||
})(GenericReceiver);
|
||||
|
||||
exports.GenericReceiver = GenericReceiver;
|
||||
|
||||
exports.Transport = Transport;
|
||||
|
||||
exports.Session = Session;
|
||||
|
||||
exports.ResponseReceiver = ResponseReceiver;
|
||||
|
||||
exports.SockJSConnection = SockJSConnection;
|
||||
|
||||
}).call(this);
|
154
node_modules/sockjs/lib/utils.js
generated
vendored
Normal file
154
node_modules/sockjs/lib/utils.js
generated
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
(function() {
|
||||
var array_intersection, crypto, escapable, lookup, rbytes, unroll_lookup;
|
||||
|
||||
crypto = require('crypto');
|
||||
|
||||
try {
|
||||
rbytes = require('rbytes');
|
||||
} catch (x) {
|
||||
|
||||
}
|
||||
|
||||
exports.array_intersection = array_intersection = function(arr_a, arr_b) {
|
||||
var a, r, _i, _len;
|
||||
r = [];
|
||||
for (_i = 0, _len = arr_a.length; _i < _len; _i++) {
|
||||
a = arr_a[_i];
|
||||
if (arr_b.indexOf(a) !== -1) r.push(a);
|
||||
}
|
||||
return r;
|
||||
};
|
||||
|
||||
exports.escape_selected = function(str, chars) {
|
||||
var c, i, map, parts, r, v, _i, _len, _ref;
|
||||
map = {};
|
||||
chars = '%' + chars;
|
||||
for (_i = 0, _len = chars.length; _i < _len; _i++) {
|
||||
c = chars[_i];
|
||||
map[c] = escape(c);
|
||||
}
|
||||
r = new RegExp('([' + chars + '])');
|
||||
parts = str.split(r);
|
||||
for (i = 0, _ref = parts.length; 0 <= _ref ? i < _ref : i > _ref; 0 <= _ref ? i++ : i--) {
|
||||
v = parts[i];
|
||||
if (v.length === 1 && v in map) parts[i] = map[v];
|
||||
}
|
||||
return parts.join('');
|
||||
};
|
||||
|
||||
exports.buffer_concat = function(buf_a, buf_b) {
|
||||
var dst;
|
||||
dst = new Buffer(buf_a.length + buf_b.length);
|
||||
buf_a.copy(dst);
|
||||
buf_b.copy(dst, buf_a.length);
|
||||
return dst;
|
||||
};
|
||||
|
||||
exports.md5_hex = function(data) {
|
||||
return crypto.createHash('md5').update(data).digest('hex');
|
||||
};
|
||||
|
||||
exports.sha1_base64 = function(data) {
|
||||
return crypto.createHash('sha1').update(data).digest('base64');
|
||||
};
|
||||
|
||||
exports.timeout_chain = function(arr) {
|
||||
var fun, timeout, user_fun, _ref,
|
||||
_this = this;
|
||||
arr = arr.slice(0);
|
||||
if (!arr.length) return;
|
||||
_ref = arr.shift(), timeout = _ref[0], user_fun = _ref[1];
|
||||
fun = function() {
|
||||
user_fun();
|
||||
return exports.timeout_chain(arr);
|
||||
};
|
||||
return setTimeout(fun, timeout);
|
||||
};
|
||||
|
||||
exports.objectExtend = function(dst, src) {
|
||||
var k;
|
||||
for (k in src) {
|
||||
if (src.hasOwnProperty(k)) dst[k] = src[k];
|
||||
}
|
||||
return dst;
|
||||
};
|
||||
|
||||
exports.overshadowListeners = function(ee, event, handler) {
|
||||
var new_handler, old_listeners;
|
||||
old_listeners = ee.listeners(event).slice(0);
|
||||
ee.removeAllListeners(event);
|
||||
new_handler = function() {
|
||||
var listener, _i, _len;
|
||||
if (handler.apply(this, arguments) !== true) {
|
||||
for (_i = 0, _len = old_listeners.length; _i < _len; _i++) {
|
||||
listener = old_listeners[_i];
|
||||
listener.apply(this, arguments);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
};
|
||||
return ee.addListener(event, new_handler);
|
||||
};
|
||||
|
||||
escapable = /[\x00-\x1f\ud800-\udfff\u200c-\u200f\u2028-\u202f\u2060-\u206f\ufff0-\uffff]/g;
|
||||
|
||||
unroll_lookup = function(escapable) {
|
||||
var c, i, unrolled;
|
||||
unrolled = {};
|
||||
c = (function() {
|
||||
var _results;
|
||||
_results = [];
|
||||
for (i = 0; i < 65536; i++) {
|
||||
_results.push(String.fromCharCode(i));
|
||||
}
|
||||
return _results;
|
||||
})();
|
||||
escapable.lastIndex = 0;
|
||||
c.join('').replace(escapable, function(a) {
|
||||
return unrolled[a] = '\\u' + ('0000' + a.charCodeAt(0).toString(16)).slice(-4);
|
||||
});
|
||||
return unrolled;
|
||||
};
|
||||
|
||||
lookup = unroll_lookup(escapable);
|
||||
|
||||
exports.quote = function(string) {
|
||||
var quoted;
|
||||
quoted = JSON.stringify(string);
|
||||
escapable.lastIndex = 0;
|
||||
if (!escapable.test(quoted)) return quoted;
|
||||
return quoted.replace(escapable, function(a) {
|
||||
return lookup[a];
|
||||
});
|
||||
};
|
||||
|
||||
exports.parseCookie = function(cookie_header) {
|
||||
var cookie, cookies, parts, _i, _len, _ref;
|
||||
cookies = {};
|
||||
if (cookie_header) {
|
||||
_ref = cookie_header.split(';');
|
||||
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
|
||||
cookie = _ref[_i];
|
||||
parts = cookie.split('=');
|
||||
cookies[parts[0].trim()] = (parts[1] || '').trim();
|
||||
}
|
||||
}
|
||||
return cookies;
|
||||
};
|
||||
|
||||
exports.random32 = function() {
|
||||
var foo, v;
|
||||
if (rbytes) {
|
||||
foo = rbytes.randomBytes(4);
|
||||
v = [foo[0], foo[1], foo[2], foo[3]];
|
||||
} else {
|
||||
foo = function() {
|
||||
return Math.floor(Math.random() * 256);
|
||||
};
|
||||
v = [foo(), foo(), foo(), foo()];
|
||||
}
|
||||
return v[0] + (v[1] * 256) + (v[2] * 256 * 256) + (v[3] * 256 * 256 * 256);
|
||||
};
|
||||
|
||||
}).call(this);
|
283
node_modules/sockjs/lib/webjs.js
generated
vendored
Normal file
283
node_modules/sockjs/lib/webjs.js
generated
vendored
Normal file
@@ -0,0 +1,283 @@
|
||||
(function() {
|
||||
var GenericApp, execute_request, fake_response, fs, http, querystring, url, utils;
|
||||
|
||||
url = require('url');
|
||||
|
||||
querystring = require('querystring');
|
||||
|
||||
fs = require('fs');
|
||||
|
||||
http = require('http');
|
||||
|
||||
utils = require('./utils');
|
||||
|
||||
execute_request = function(app, funs, req, res, data) {
|
||||
var fun, _results;
|
||||
try {
|
||||
_results = [];
|
||||
while (funs.length > 0) {
|
||||
fun = funs.shift();
|
||||
req.last_fun = fun;
|
||||
_results.push(data = app[fun](req, res, data, req.next_filter));
|
||||
}
|
||||
return _results;
|
||||
} catch (x) {
|
||||
if (typeof x === 'object' && 'status' in x) {
|
||||
if (x.status === 0) {
|
||||
return;
|
||||
} else if ('handle_' + x.status in app) {
|
||||
app['handle_' + x.status](req, res, x);
|
||||
} else {
|
||||
app['handle_error'](req, res, x);
|
||||
}
|
||||
} else {
|
||||
app['handle_error'](req, res, x);
|
||||
}
|
||||
return app['log_request'](req, res, true);
|
||||
}
|
||||
};
|
||||
|
||||
fake_response = function(req, res) {
|
||||
var headers;
|
||||
headers = {
|
||||
'Connection': 'close'
|
||||
};
|
||||
res.writeHead = function(status, user_headers) {
|
||||
var k, r;
|
||||
if (user_headers == null) user_headers = {};
|
||||
r = [];
|
||||
r.push('HTTP/' + req.httpVersion + ' ' + status + ' ' + http.STATUS_CODES[status]);
|
||||
utils.objectExtend(headers, user_headers);
|
||||
for (k in headers) {
|
||||
r.push(k + ': ' + headers[k]);
|
||||
}
|
||||
r = r.concat(['', '']);
|
||||
try {
|
||||
res.write(r.join('\r\n'));
|
||||
} catch (x) {
|
||||
|
||||
}
|
||||
try {
|
||||
return res.end();
|
||||
} catch (x) {
|
||||
|
||||
}
|
||||
};
|
||||
return res.setHeader = function(k, v) {
|
||||
return headers[k] = v;
|
||||
};
|
||||
};
|
||||
|
||||
exports.generateHandler = function(app, dispatcher) {
|
||||
return function(req, res, head) {
|
||||
var allowed_methods, found, funs, i, m, method, path, row, _i, _len, _ref;
|
||||
if (typeof res.writeHead === "undefined") fake_response(req, res);
|
||||
utils.objectExtend(req, url.parse(req.url, true));
|
||||
req.start_date = new Date();
|
||||
found = false;
|
||||
allowed_methods = [];
|
||||
for (_i = 0, _len = dispatcher.length; _i < _len; _i++) {
|
||||
row = dispatcher[_i];
|
||||
method = row[0], path = row[1], funs = row[2];
|
||||
if (path.constructor !== Array) path = [path];
|
||||
m = req.pathname.match(path[0]);
|
||||
if (!m) continue;
|
||||
if (!req.method.match(new RegExp(method))) {
|
||||
allowed_methods.push(method);
|
||||
continue;
|
||||
}
|
||||
for (i = 1, _ref = path.length; 1 <= _ref ? i < _ref : i > _ref; 1 <= _ref ? i++ : i--) {
|
||||
req[path[i]] = m[i];
|
||||
}
|
||||
funs = funs.slice(0);
|
||||
funs.push('log_request');
|
||||
req.next_filter = function(data) {
|
||||
return execute_request(app, funs, req, res, data);
|
||||
};
|
||||
req.next_filter(head);
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
if (!found) {
|
||||
if (allowed_methods.length !== 0) {
|
||||
app['handle_405'](req, res, allowed_methods);
|
||||
} else {
|
||||
app['handle_404'](req, res);
|
||||
}
|
||||
app['log_request'](req, res, true);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
exports.GenericApp = GenericApp = (function() {
|
||||
|
||||
function GenericApp() {}
|
||||
|
||||
GenericApp.prototype.handle_404 = function(req, res, x) {
|
||||
if (res.finished) return x;
|
||||
res.writeHead(404, {});
|
||||
res.end();
|
||||
return true;
|
||||
};
|
||||
|
||||
GenericApp.prototype.handle_405 = function(req, res, methods) {
|
||||
res.writeHead(405, {
|
||||
'Allow': methods.join(', ')
|
||||
});
|
||||
res.end();
|
||||
return true;
|
||||
};
|
||||
|
||||
GenericApp.prototype.handle_error = function(req, res, x) {
|
||||
if (res.finished) return x;
|
||||
if (typeof x === 'object' && 'status' in x) {
|
||||
res.writeHead(x.status, {});
|
||||
res.end(x.message || "");
|
||||
} else {
|
||||
try {
|
||||
res.writeHead(500, {});
|
||||
res.end("500 - Internal Server Error");
|
||||
} catch (x) {
|
||||
|
||||
}
|
||||
this.log('error', 'Exception on "' + req.method + ' ' + req.href + '" in filter "' + req.last_fun + '":\n' + (x.stack || x));
|
||||
}
|
||||
return true;
|
||||
};
|
||||
|
||||
GenericApp.prototype.log_request = function(req, res, data) {
|
||||
var td;
|
||||
td = (new Date()) - req.start_date;
|
||||
this.log('info', req.method + ' ' + req.url + ' ' + td + 'ms ' + (res.finished ? res._header.split('\r')[0].split(' ')[1] : '(unfinished)'));
|
||||
return data;
|
||||
};
|
||||
|
||||
GenericApp.prototype.log = function(severity, line) {
|
||||
return console.log(line);
|
||||
};
|
||||
|
||||
GenericApp.prototype.expose_html = function(req, res, content) {
|
||||
if (res.finished) return content;
|
||||
if (!res.getHeader('Content-Type')) {
|
||||
res.setHeader('Content-Type', 'text/html; charset=UTF-8');
|
||||
}
|
||||
return this.expose(req, res, content);
|
||||
};
|
||||
|
||||
GenericApp.prototype.expose_json = function(req, res, content) {
|
||||
if (res.finished) return content;
|
||||
if (!res.getHeader('Content-Type')) {
|
||||
res.setHeader('Content-Type', 'application/json');
|
||||
}
|
||||
return this.expose(req, res, JSON.stringify(content));
|
||||
};
|
||||
|
||||
GenericApp.prototype.expose = function(req, res, content) {
|
||||
if (res.finished) return content;
|
||||
if (content && !res.getHeader('Content-Type')) {
|
||||
res.setHeader('Content-Type', 'text/plain');
|
||||
}
|
||||
if (content) res.setHeader('Content-Length', content.length);
|
||||
res.writeHead(res.statusCode);
|
||||
res.end(content, 'utf8');
|
||||
return true;
|
||||
};
|
||||
|
||||
GenericApp.prototype.serve_file = function(req, res, filename, next_filter) {
|
||||
var a;
|
||||
a = function(error, content) {
|
||||
if (error) {
|
||||
res.writeHead(500);
|
||||
res.end("can't read file");
|
||||
} else {
|
||||
res.setHeader('Content-length', content.length);
|
||||
res.writeHead(res.statusCode, res.headers);
|
||||
res.end(content, 'utf8');
|
||||
}
|
||||
return next_filter(true);
|
||||
};
|
||||
fs.readFile(filename, a);
|
||||
throw {
|
||||
status: 0
|
||||
};
|
||||
};
|
||||
|
||||
GenericApp.prototype.cache_for = function(req, res, content) {
|
||||
var exp;
|
||||
res.cache_for = res.cache_for || 365 * 24 * 60 * 60;
|
||||
res.setHeader('Cache-Control', 'public, max-age=' + res.cache_for);
|
||||
exp = new Date();
|
||||
exp.setTime(exp.getTime() + res.cache_for * 1000);
|
||||
res.setHeader('Expires', exp.toGMTString());
|
||||
return content;
|
||||
};
|
||||
|
||||
GenericApp.prototype.h_no_cache = function(req, res, content) {
|
||||
res.setHeader('Cache-Control', 'no-store, no-cache, must-revalidate, max-age=0');
|
||||
return content;
|
||||
};
|
||||
|
||||
GenericApp.prototype.expect_form = function(req, res, _data, next_filter) {
|
||||
var data,
|
||||
_this = this;
|
||||
data = new Buffer(0);
|
||||
req.on('data', function(d) {
|
||||
return data = utils.buffer_concat(data, new Buffer(d, 'binary'));
|
||||
});
|
||||
req.on('end', function() {
|
||||
var q;
|
||||
data = data.toString('utf-8');
|
||||
switch ((req.headers['content-type'] || '').split(';')[0]) {
|
||||
case 'application/x-www-form-urlencoded':
|
||||
q = querystring.parse(data);
|
||||
break;
|
||||
case 'text/plain':
|
||||
case '':
|
||||
q = data;
|
||||
break;
|
||||
default:
|
||||
_this.log('error', "Unsupported content-type " + req.headers['content-type']);
|
||||
q = void 0;
|
||||
}
|
||||
return next_filter(q);
|
||||
});
|
||||
throw {
|
||||
status: 0
|
||||
};
|
||||
};
|
||||
|
||||
GenericApp.prototype.expect_xhr = function(req, res, _data, next_filter) {
|
||||
var data,
|
||||
_this = this;
|
||||
data = new Buffer(0);
|
||||
req.on('data', function(d) {
|
||||
return data = utils.buffer_concat(data, new Buffer(d, 'binary'));
|
||||
});
|
||||
req.on('end', function() {
|
||||
var q;
|
||||
data = data.toString('utf-8');
|
||||
switch ((req.headers['content-type'] || '').split(';')[0]) {
|
||||
case 'text/plain':
|
||||
case 'T':
|
||||
case 'application/json':
|
||||
case 'application/xml':
|
||||
case '':
|
||||
case 'text/xml':
|
||||
q = data;
|
||||
break;
|
||||
default:
|
||||
_this.log('error', 'Unsupported content-type ' + req.headers['content-type']);
|
||||
q = void 0;
|
||||
}
|
||||
return next_filter(q);
|
||||
});
|
||||
throw {
|
||||
status: 0
|
||||
};
|
||||
};
|
||||
|
||||
return GenericApp;
|
||||
|
||||
})();
|
||||
|
||||
}).call(this);
|
Reference in New Issue
Block a user