Skip to content

Commit 3468a19

Browse files
committedAug 2, 2023
fix(webtransport): properly handle WebTransport-only connections
A WebTransport-only connection has no `request` attribute, so we need to handle that case.
1 parent 09d4549 commit 3468a19

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed
 

‎lib/socket.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,16 @@ export class Socket<
292292
*/
293293
private buildHandshake(auth: object): Handshake {
294294
return {
295-
headers: this.request.headers,
295+
headers: this.request?.headers || {},
296296
time: new Date() + "",
297297
address: this.conn.remoteAddress,
298-
xdomain: !!this.request.headers.origin,
298+
xdomain: !!this.request?.headers.origin,
299299
// @ts-ignore
300-
secure: !!this.request.connection.encrypted,
300+
secure: !this.request || !!this.request.connection.encrypted,
301301
issued: +new Date(),
302-
url: this.request.url!,
302+
url: this.request?.url!,
303303
// @ts-ignore
304-
query: this.request._query,
304+
query: this.request?._query || {},
305305
auth,
306306
};
307307
}

‎test/socket.ts

+17
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,23 @@ describe("socket", () => {
684684
});
685685
});
686686

687+
it("should handshake a client without access to the Engine.IO request (WebTransport-only connection)", (done) => {
688+
const io = new Server(0);
689+
const clientSocket = createClient(io, "/");
690+
691+
io.engine.on("connection", (socket) => {
692+
delete socket.request;
693+
});
694+
695+
io.on("connection", (socket) => {
696+
expect(socket.handshake.secure).to.be(true);
697+
expect(socket.handshake.headers).to.eql({});
698+
expect(socket.handshake.query).to.eql({});
699+
700+
success(done, io, clientSocket);
701+
});
702+
});
703+
687704
it("should handle very large json", function (done) {
688705
this.timeout(30000);
689706
const io = new Server(0, { perMessageDeflate: false });

0 commit comments

Comments
 (0)
Please sign in to comment.