Can't set response headers in Server.handleUpgrade
维护者通常 2 天内回复
评估
- 难度
- 2/5
- 预计耗时
- 1-3 小时
- 新手友好度
- 72/100
- Issue 类型
- 缺陷
- 描述清晰度
- 描述清楚
- 活跃度
- 冷清
- 技术栈
- nodejs, typescript
调研方向
从 packages/engine.io/lib/server.ts 中唯一的 kResponseHeaders 定义以及 713–732 行附近 Server.handleUpgrade 对 response header 的处理开始。将其与 engine.io README 中显式请求的用法进行比较;完成标准是用户代码可以提供额外的 upgrade response header,并且文档中的 CORS 示例无需 cors middleware 即可正常工作。
由索引模型根据 Issue 内容生成。
描述
Describe the bug
It's not possible to specify headers for an upgrade response that is handled by Server.handleUpgrade.
To Reproduce
Follow the usage example where requests are passed in explicitly:
https://github.com/socketio/socket.io/blob/439a8f669c6788b512dd76011c4476830d67515b/packages/engine.io/README.md?plain=1#L40-L58
Using this example it's not possible to specify the upgrade response headers. Specifically, it's not possible to set the CORS headers without using the .cors "middleware" option. Since https://github.com/socketio/socket.io/commit/d1f5aa93722a7f1ed729b96f771daf92a3dfdaf7 using the .cors "middleware" option breaks webtransport, so the only way to make it work is to remove the .cors option and set them up manually.
Expected behavior
It should be possible to set any headers for the upgrade response that is sent out when upgrade is handled by engine.io.
Engine.IO currently uses the kResponseHeaders key on the request object to specify additional headers to send in the upgrade response:
https://github.com/socketio/socket.io/blob/439a8f669c6788b512dd76011c4476830d67515b/packages/engine.io/lib/server.ts#L713-L732
I expected it to be possible to set them up from my code in a similar way:
const kResponseHeaders = Symbol.for("responseHeaders");
server.on("upgrade", (req, socket, head) => {
if (req.url?.startsWith("/engine.io/")) {
req[kResponseHeaders] = {
"Access-Control-Allow-Origin": req.headers["origin"] || "*",
"Access-Control-Allow-Credentials": "true"
};
return eio.handleUpgrade(req, socket, head);
}
// ...
});
But it is currently defined as a unique Symbol, which prevents above code from working:
https://github.com/socketio/socket.io/blob/439a8f669c6788b512dd76011c4476830d67515b/packages/engine.io/lib/server.ts#L27
The new definition can use Symbol.for instead to allow user code to specify extra headers for the websocket upgrade response.
- 主要语言
- TypeScript
- 星标
- 63.2k
- 派生
- 10.3k
- 平均合并
- 3 小时 24 分钟
- 30 天内合并 PR
- 1
环境准备
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
socketio/socket.io 的其他 Issue
-
难度 1/5 1-3 小时 新手友好度 78/100
维护者通常 2 天内回复
-
WebTransport ignores query parameters in URL可能已有人在做 @cyphercodes 于 149 天前认领。 未关闭needs major release question
难度 2/5 1-3 小时 新手友好度 68/100
socketio/socket.io#5496 · 3 条评论 ·
维护者通常 2 天内回复
-
"Basic CRUD application" can't be started with Angular client可能已有人在做 @lazerg 于 7 天前认领。 未关闭to triage
难度 3/5 1-2 天 新手友好度 65/100
维护者通常 2 天内回复
-
Connection State Recovery fails if client reconnects before server emits any events ("Zero-Event" reconnect)可能已有人在做 @marwan562 于 50 天前认领。 未关闭enhancement
难度 4/5 3-5 天 新手友好度 56/100
socketio/socket.io#5538 · 1 条评论 ·
维护者通常 2 天内回复
-
enhancement
难度 5/5 一周以上 新手友好度 35/100
socketio/socket.io#5512 · 6 条评论 · 4 个 reaction ·
维护者通常 2 天内回复
查看 socketio/socket.io 的全部 Issue
相似的 Issue
-
affected/v17 affected/v18 area/frontend type/bug
难度 2/5 1-3 小时 新手友好度 82/100
umbraco/Umbraco-CMS#24186 ·
维护者通常 2 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
better-auth/better-auth#11723 · 1 个 reaction ·
维护者通常 1 天内回复
-
area: docs difficulty: easy documentation good first issue
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复
-
Worker-Erstellung bricht langsame Git-Worktree-Checkouts nach 20 Sekunden ab可能已有人在做 @KajoVanBuyten 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 69/100
AgentSystemLabs/agent-office#367 ·
维护者通常 1 天内回复