HTTP websocket compression fix.
Ylian Saint-Hilaire committed
Jul 10, 2020 at 00:51 UTC
02de0c58ad18da9f1be7fd50941538b610412af1
1 file changed
+4
-8
webserver.js
+4
-8
@@ -4300,14 +4300,10 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4300
4301
// Starts the HTTPS server, this should be called after the user/mesh tables are loaded
4302
function serverStart() {
4303
- // Setup websocket options if needed.
4304
- var webSocketOptions;
4305
- if (args.wscompression === true) { webSocketOptions = { wsOptions: { perMessageDeflate: true } } }
4306
-
4303
// Start the server, only after users and meshes are loaded from the database.
4304
if (obj.args.notls || obj.args.tlsoffload) {
4305
// Setup the HTTP server without TLS
4310
- obj.expressWs = require('express-ws')(obj.app, webSocketOptions);
4306
+ obj.expressWs = require('express-ws')(obj.app, null, { wsOptions: { perMessageDeflate: (args.wscompression === true) } });
4307
} else {
4308
// Setup the HTTP server with TLS, use only TLS 1.2 and higher with perfect forward secrecy (PFS).
4309
//const tlsOptions = { cert: obj.certificates.web.cert, key: obj.certificates.web.key, ca: obj.certificates.web.ca, rejectUnauthorized: true, ciphers: "HIGH:!aNULL:!eNULL:!EXPORT:!RSA:!DES:!RC4:!MD5:!PSK:!SRP:!CAMELLIA", secureOptions: constants.SSL_OP_NO_SSLv2 | constants.SSL_OP_NO_SSLv3 | constants.SSL_OP_NO_COMPRESSION | constants.SSL_OP_CIPHER_SERVER_PREFERENCE | constants.SSL_OP_NO_TLSv1 | constants.SSL_OP_NO_TLSv1_1 }; // This does not work with TLS 1.3
@@ -4319,7 +4315,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4315
//obj.tlsServer.on('tlsClientError', function (err) { console.log('tlsClientError', err); });
4316
obj.tlsServer.on('newSession', function (id, data, cb) { if (tlsSessionStoreCount > 1000) { tlsSessionStoreCount = 0; tlsSessionStore = {}; } tlsSessionStore[id.toString('hex')] = data; tlsSessionStoreCount++; cb(); });
4317
obj.tlsServer.on('resumeSession', function (id, cb) { cb(null, tlsSessionStore[id.toString('hex')] || null); });
4322
- obj.expressWs = require('express-ws')(obj.app, obj.tlsServer, webSocketOptions);
4318
+ obj.expressWs = require('express-ws')(obj.app, obj.tlsServer, { wsOptions: { perMessageDeflate: (args.wscompression === true) } });
4319
}
4320
4321
// Start a second agent-only server if needed
@@ -4332,7 +4328,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4328
4329
if (agentPortTls == false) {
4330
// Setup the HTTP server without TLS
4335
- obj.expressWsAlt = require('express-ws')(obj.agentapp, webSocketOptions);
4331
+ obj.expressWsAlt = require('express-ws')(obj.agentapp, null, { wsOptions: { perMessageDeflate: (args.wscompression === true) } });
4332
} else {
4333
// Setup the agent HTTP server with TLS, use only TLS 1.2 and higher with perfect forward secrecy (PFS).
4334
// If TLS is used on the agent port, we always use the default TLS certificate.
@@ -4343,7 +4339,7 @@ module.exports.CreateWebServer = function (parent, db, args, certificates) {
4339
//obj.tlsAltServer.on('tlsClientError', function (err) { console.log('tlsClientError', err); });
4340
obj.tlsAltServer.on('newSession', function (id, data, cb) { if (tlsSessionStoreCount > 1000) { tlsSessionStoreCount = 0; tlsSessionStore = {}; } tlsSessionStore[id.toString('hex')] = data; tlsSessionStoreCount++; cb(); });
4341
obj.tlsAltServer.on('resumeSession', function (id, cb) { cb(null, tlsSessionStore[id.toString('hex')] || null); });
4346
- obj.expressWsAlt = require('express-ws')(obj.agentapp, obj.tlsAltServer, webSocketOptions);
4342
+ obj.expressWsAlt = require('express-ws')(obj.agentapp, obj.tlsAltServer, { wsOptions: { perMessageDeflate: (args.wscompression === true) } });
4343
}
4344
}
4345