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
This commit is contained in:
Damien Arrachequesne
2022-03-10 14:01:40 +01:00
parent 657f04e0b8
commit 088dcb4dff
2 changed files with 5 additions and 3 deletions

View File

@@ -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
})
);

View File

@@ -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/`)