百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
返回工具页/返回 Issues 列表
#43106·bun

Bun.serve: Bun.file() 路由会从 Response 中原文发送 Transfer-Encoding 或 Content-Length 头

作者: robobun创建于 2026年9月17日更新于 2026年9月17日

Bun的哪个版本在运行?

1.4.3-canary.1+c6b7fcb5b. ary. 主机上630e921db0的代码相同.

你的电脑是什么平台?

Linux x64 函数

  • 什么步骤可以复制虫子?

{\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你来干什么? // file-framing.mjs (英语). 从“ 节点: net” 导入网; 从“ 节点:fs” 导入 fs; 从“ node:os” 导入 os; 从“ 节点: path” 导入路径;

const dir = fs.mkdtempSync(path.join (os.tmpdir (),"file-framing -")); ; 音译为"相通". const p = path.join(dir,"a.txt"); 2. fs.writeFileSync(p, “文件体” );

const 服务器 = Bun. serve({ 端口: 0, 并且 主机名:"127.0.0.1", 路线 : { "/file-te":新回应(Bun.file(p),{标题:{"传输-编码":"被")}, "/file-cl":新的响应(Bun.file (p),{标题:{"Content-Length":"3"}), "/static-te":新反应("文件-正体",{标题:{"传输-编码":"被"),}, "/static-cl":新反应 ("文件-正文",{标题:{"Content-Length":"3"}), {\fn华文楷体\fs16\1cHE0E0E0} 获取 : () QQ 新的响应( “ 倒回 ” ) ,

  • ;

async 函数原始( pathname) { c. 与 Resolvers (); (一) 让buf = ""; Const s = net.connect(server.port,"127.0.0.1", () QQ s.write(`GET ${pathname} HTTP/1.1\r\n\nHost: x\r\n 连接: close\r\n\n' ), (三) s.on ("data", d => (buf += d.toString ("latin1"))"); ; ; ; ; s.on ("错误", () =>; s.on("接近",决心); 等待诺言; const [头,. body] = buf.split ("\r\n"; const framing = head.split ("\r\n"). filter (l = /^ (content-word-Xxtrans-encoding):/i.test(l)); ). contail.log(pathname.padEnd(12),JSON.stringify({框架,正文:body.join ("\r\n\r\n")})); {\fn黑体\fs22\bord1\shad0\3aHBE\4aH00\fscx67\fscy66\2cHFFFFFF\3cH808080}你觉得呢? (c) 等待(r); 服务器。 stop( true) ; fs.rmSync( dir, {递归: true, struction: true }) ;


运行"bun file-framing.mjs".

什么是预期的行为?

路由从文件中计算出框架 。 所有四条路线都发送了 " Content-Length:9 " 和 " Transfer-Encoding " 。 两条静止的 " 反应 " 路线已经这样做了。

你看见什么了?

/file-te {"花香":["变相-编码:块",内容-长度:9"],"体":"花相-体"] /file-cl {"香": ["Content-Length: 3"]"身体":"file-body"] /static-te {"花香":["Content-Length:9"]"身体":"文件-身体"] /static-cl {"花香": ["Content-Length: 9"]"身体":"File-body"]


- `/文件-te ' 发送`传送-编码:块'与`内容-长度'一起,而机体没有块编码。 RFC 9112 6.2在一通留言中禁止两个头. 服从`传送-编码 ' 的客户将`文件-机构 ' 读作块大小而失败。
- `/file-cl'声明3字节并发送9个字节。 在保持-活性连接上,客户端读取了其他6字节作为下个响应的开始.

补充资料

`StaticRoute: from js' (`src/runtime/server/StaticRoute.rs:209')将`传送-编码 ' 和`Content-Length'从`Response ' 标题中删除,然后才取出快照。 `FileRoute: from js' (`src/runtime/ server/FileRoute.rs:132')不作改动取出快照,而`FileRoute:write headers'取出快照。
. . . . . . .

内容来源: oven-sh/bun

查看 GitHub 原文在 GitHub 查看讨论