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

lib/socket.ts

Lines changed: 2 additions & 1 deletion
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

test/server.js

Lines changed: 3 additions & 2 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy