Skip to content

Commit 5ad2736

Browse files
committedDec 30, 2020
feat: disable perMessageDeflate by default
The WebSocket permessage-deflate extension, while useful is some cases, adds some extra memory overhead for each WebSocket connection, and results in huge memory usage in production deployments. It will now be disabled by default. Backported from master: 078527a
1 parent f632269 commit 5ad2736

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed
 

‎README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ to a single process.
239239
- `allowUpgrades` (`Boolean`): whether to allow transport upgrades
240240
(`true`)
241241
- `perMessageDeflate` (`Object|Boolean`): parameters of the WebSocket permessage-deflate extension
242-
(see [ws module](https://github.com/einaros/ws) api docs). Set to `false` to disable. (`true`)
242+
(see [ws module](https://github.com/einaros/ws) api docs). Set to `true` to enable. (`false`)
243243
- `threshold` (`Number`): data is compressed only if the byte size is above this value (`1024`)
244244
- `httpCompression` (`Object|Boolean`): parameters of the http compression for the polling transports
245245
(see [zlib](http://nodejs.org/api/zlib.html#zlib_options) api docs). Set to `false` to disable. (`true`)

‎lib/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ function Server (opts) {
4747
this.cookie = false !== opts.cookie ? (opts.cookie || 'io') : false;
4848
this.cookiePath = false !== opts.cookiePath ? (opts.cookiePath || '/') : false;
4949
this.cookieHttpOnly = false !== opts.cookieHttpOnly;
50-
this.perMessageDeflate = false !== opts.perMessageDeflate ? (opts.perMessageDeflate || true) : false;
50+
this.perMessageDeflate = opts.perMessageDeflate || false;
5151
this.httpCompression = false !== opts.httpCompression ? (opts.httpCompression || {}) : false;
5252
this.initialPacket = opts.initialPacket;
5353

‎test/server.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -2503,7 +2503,7 @@ describe('server', function () {
25032503
});
25042504

25052505
it('should not compress when the byte size is below threshold', function (done) {
2506-
var engine = listen({ transports: ['websocket'] }, function (port) {
2506+
var engine = listen({ transports: ['websocket'], perMessageDeflate: true }, function (port) {
25072507
engine.on('connection', function (conn) {
25082508
var socket = conn.transport.socket;
25092509
var send = socket.send;

0 commit comments

Comments
 (0)
Please sign in to comment.