Skip to content

Commit

Permalink
feat: disable perMessageDeflate by default
Browse files Browse the repository at this point in the history
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
  • Loading branch information
darrachequesne committed Dec 30, 2020
1 parent f632269 commit 5ad2736
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ to a single process.
- `allowUpgrades` (`Boolean`): whether to allow transport upgrades
(`true`)
- `perMessageDeflate` (`Object|Boolean`): parameters of the WebSocket permessage-deflate extension
(see [ws module](https://github.com/einaros/ws) api docs). Set to `false` to disable. (`true`)
(see [ws module](https://github.com/einaros/ws) api docs). Set to `true` to enable. (`false`)
- `threshold` (`Number`): data is compressed only if the byte size is above this value (`1024`)
- `httpCompression` (`Object|Boolean`): parameters of the http compression for the polling transports
(see [zlib](http://nodejs.org/api/zlib.html#zlib_options) api docs). Set to `false` to disable. (`true`)
Expand Down
2 changes: 1 addition & 1 deletion lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ function Server (opts) {
this.cookie = false !== opts.cookie ? (opts.cookie || 'io') : false;
this.cookiePath = false !== opts.cookiePath ? (opts.cookiePath || '/') : false;
this.cookieHttpOnly = false !== opts.cookieHttpOnly;
this.perMessageDeflate = false !== opts.perMessageDeflate ? (opts.perMessageDeflate || true) : false;
this.perMessageDeflate = opts.perMessageDeflate || false;
this.httpCompression = false !== opts.httpCompression ? (opts.httpCompression || {}) : false;
this.initialPacket = opts.initialPacket;

Expand Down
2 changes: 1 addition & 1 deletion test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -2503,7 +2503,7 @@ describe('server', function () {
});

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

0 comments on commit 5ad2736

Please sign in to comment.