Skip to content

Commit 088dcb4

Browse files
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: socketio/socket.io-client#1531
1 parent 657f04e commit 088dcb4

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

Diff for: lib/socket.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,8 @@ export class Socket extends EventEmitter {
9090
sid: this.id,
9191
upgrades: this.getAvailableUpgrades(),
9292
pingInterval: this.server.opts.pingInterval,
93-
pingTimeout: this.server.opts.pingTimeout
93+
pingTimeout: this.server.opts.pingTimeout,
94+
maxPayload: this.server.opts.maxHttpBufferSize
9495
})
9596
);
9697

Diff for: test/server.js

+3-2
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,7 @@ describe("server", () => {
449449
expect(obj.sid).to.be.a("string");
450450
expect(obj.pingTimeout).to.be.a("number");
451451
expect(obj.upgrades).to.be.an("array");
452+
expect(obj.maxPayload).to.eql(1000000);
452453
done();
453454
});
454455
});
@@ -3356,7 +3357,7 @@ describe("server", () => {
33563357
expect(res.headers["set-cookie"].length).to.be(2);
33573358
expect(res.headers["set-cookie"][1]).to.be("mycookie=456");
33583359

3359-
const sid = JSON.parse(res.text.substring(4)).sid;
3360+
const sid = JSON.parse(res.text.substring(5)).sid;
33603361

33613362
request
33623363
.post(`http://localhost:${port}/engine.io/`)
@@ -3393,7 +3394,7 @@ describe("server", () => {
33933394
expect(res.headers["set-cookie"].length).to.be(2);
33943395
expect(res.headers["set-cookie"][1]).to.be("mycookie=456");
33953396

3396-
const sid = JSON.parse(res.text.substring(4)).sid;
3397+
const sid = JSON.parse(res.text.substring(5)).sid;
33973398

33983399
request
33993400
.post(`http://localhost:${port}/engine.io/`)

0 commit comments

Comments
 (0)