Skip to content

Commit

Permalink
refactor: do not include the pid by default
Browse files Browse the repository at this point in the history
So that the client knows whether the connection state recovery feature
is enabled.

See also: 54d5ee0
  • Loading branch information
darrachequesne committed Jan 25, 2023
1 parent 0c0eb00 commit 115a981
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,9 @@ export class Socket<
} else {
this.id = base64id.generateId(); // don't reuse the Engine.IO id because it's sensitive information
}
this.pid = base64id.generateId();
if (this.server._opts.connectionStateRecovery) {
this.pid = base64id.generateId();
}
}
this.handshake = this.buildHandshake(auth);
}
Expand Down
22 changes: 22 additions & 0 deletions test/connection-state-recovery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,4 +193,26 @@ describe("connection state recovery", () => {

io.close();
});

it("should be disabled by default", async () => {
const httpServer = createServer().listen(0);
const io = new Server(httpServer);

// Engine.IO handshake
const sid = await eioHandshake(httpServer);

// Socket.IO handshake
await eioPush(httpServer, sid, "40");

const handshakeBody = await eioPoll(httpServer, sid);

expect(handshakeBody.startsWith("40")).to.be(true);

const handshake = JSON.parse(handshakeBody.substring(2));

expect(handshake.sid).to.not.be(undefined);
expect(handshake.pid).to.be(undefined);

io.close();
});
});

0 comments on commit 115a981

Please sign in to comment.