fix(eio): emit initial_headers and headers events in uServer (#5460)

The uServer (uWebSockets.js) implementation did not emit
"initial_headers" and "headers" events during WebSocket upgrades,
unlike the regular Server which does this via the ws "headers" event.

Related: https://github.com/socketio/socket.io/issues/5300
This commit is contained in:
Erdinç Cürebal
2026-03-04 11:07:02 +03:00
committed by GitHub
parent da04267ffc
commit 44ed73f539
2 changed files with 16 additions and 8 deletions

View File

@@ -226,9 +226,23 @@ export class uServer extends BaseServer {
}
}
// emit headers events for WebSocket upgrades
const additionalHeaders = {};
const isInitialRequest = !id;
if (isInitialRequest) {
this.emit("initial_headers", additionalHeaders, req);
}
this.emit("headers", additionalHeaders, req);
// calling writeStatus() triggers the flushing of any header added in a middleware
req.res.writeStatus("101 Switching Protocols");
Object.keys(additionalHeaders).forEach((key) => {
req.res.writeHeader(key, additionalHeaders[key]);
});
res.upgrade(
{
transport,

View File

@@ -3598,10 +3598,7 @@ describe("server", () => {
});
it("should emit a 'initial_headers' event (websocket)", function (done) {
if (
process.env.EIO_WS_ENGINE === "eiows" ||
process.env.EIO_WS_ENGINE === "uws"
) {
if (process.env.EIO_WS_ENGINE === "eiows") {
return this.skip();
}
const partialDone = createPartialDone(done, 2);
@@ -3644,10 +3641,7 @@ describe("server", () => {
});
it("should emit several 'headers' events per connection", function (done) {
if (
process.env.EIO_WS_ENGINE === "eiows" ||
process.env.EIO_WS_ENGINE === "uws"
) {
if (process.env.EIO_WS_ENGINE === "eiows") {
return this.skip();
}
const partialDone = createPartialDone(done, 4);