From 088dcb4dff60df39785df13d0a33d3ceaa1dff38 Mon Sep 17 00:00:00 2001 From: Damien Arrachequesne Date: Thu, 10 Mar 2022 14:01:40 +0100 Subject: [PATCH] feat: add the "maxPayload" field in the handshake details So that clients in HTTP long-polling can decide how many packets they have to send to stay under the maxHttpBufferSize value. This is a backward compatible change which should not mandate a new major revision of the protocol (we stay in v4), as we only add a field in the JSON-encoded handshake data: ``` 0{"sid":"lv_VI97HAXpY6yYWAAAC","upgrades":["websocket"],"pingInterval":25000,"pingTimeout":5000,"maxPayload":1000000} ``` Related: https://github.com/socketio/socket.io-client/issues/1531 --- lib/socket.ts | 3 ++- test/server.js | 5 +++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/socket.ts b/lib/socket.ts index c3a81619..73b9b0f1 100644 --- a/lib/socket.ts +++ b/lib/socket.ts @@ -90,7 +90,8 @@ export class Socket extends EventEmitter { sid: this.id, upgrades: this.getAvailableUpgrades(), pingInterval: this.server.opts.pingInterval, - pingTimeout: this.server.opts.pingTimeout + pingTimeout: this.server.opts.pingTimeout, + maxPayload: this.server.opts.maxHttpBufferSize }) ); diff --git a/test/server.js b/test/server.js index fff27d58..906bdb6b 100644 --- a/test/server.js +++ b/test/server.js @@ -449,6 +449,7 @@ describe("server", () => { expect(obj.sid).to.be.a("string"); expect(obj.pingTimeout).to.be.a("number"); expect(obj.upgrades).to.be.an("array"); + expect(obj.maxPayload).to.eql(1000000); done(); }); }); @@ -3356,7 +3357,7 @@ describe("server", () => { expect(res.headers["set-cookie"].length).to.be(2); expect(res.headers["set-cookie"][1]).to.be("mycookie=456"); - const sid = JSON.parse(res.text.substring(4)).sid; + const sid = JSON.parse(res.text.substring(5)).sid; request .post(`http://localhost:${port}/engine.io/`) @@ -3393,7 +3394,7 @@ describe("server", () => { expect(res.headers["set-cookie"].length).to.be(2); expect(res.headers["set-cookie"][1]).to.be("mycookie=456"); - const sid = JSON.parse(res.text.substring(4)).sid; + const sid = JSON.parse(res.text.substring(5)).sid; request .post(`http://localhost:${port}/engine.io/`)