Skip to content

Commit

Permalink
fix(webtransport): properly handle WebTransport-only connections
Browse files Browse the repository at this point in the history
A WebTransport-only connection has no `request` attribute, so we need
to handle that case.
  • Loading branch information
darrachequesne committed Aug 2, 2023
1 parent 09d4549 commit 3468a19
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
10 changes: 5 additions & 5 deletions lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -292,16 +292,16 @@ export class Socket<
*/
private buildHandshake(auth: object): Handshake {
return {
headers: this.request.headers,
headers: this.request?.headers || {},
time: new Date() + "",
address: this.conn.remoteAddress,
xdomain: !!this.request.headers.origin,
xdomain: !!this.request?.headers.origin,
// @ts-ignore
secure: !!this.request.connection.encrypted,
secure: !this.request || !!this.request.connection.encrypted,
issued: +new Date(),
url: this.request.url!,
url: this.request?.url!,
// @ts-ignore
query: this.request._query,
query: this.request?._query || {},
auth,
};
}
Expand Down
17 changes: 17 additions & 0 deletions test/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,23 @@ describe("socket", () => {
});
});

it("should handshake a client without access to the Engine.IO request (WebTransport-only connection)", (done) => {
const io = new Server(0);
const clientSocket = createClient(io, "/");

io.engine.on("connection", (socket) => {
delete socket.request;
});

io.on("connection", (socket) => {
expect(socket.handshake.secure).to.be(true);
expect(socket.handshake.headers).to.eql({});
expect(socket.handshake.query).to.eql({});

success(done, io, clientSocket);
});
});

it("should handle very large json", function (done) {
this.timeout(30000);
const io = new Server(0, { perMessageDeflate: false });
Expand Down

0 comments on commit 3468a19

Please sign in to comment.