Skip to content

Commit

Permalink
feat: add the "maxPayload" field in the handshake details
Browse files Browse the repository at this point in the history
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: socketio/socket.io-client#1531
  • Loading branch information
darrachequesne committed Mar 10, 2022
1 parent 657f04e commit 088dcb4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
3 changes: 2 additions & 1 deletion lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
);

Expand Down
5 changes: 3 additions & 2 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
});
Expand Down Expand Up @@ -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/`)
Expand Down Expand Up @@ -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/`)
Expand Down

0 comments on commit 088dcb4

Please sign in to comment.