mirror of
https://github.com/socketio/socket.io.git
synced 2026-04-30 03:00:39 -04:00
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:
@@ -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,
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user