asgi-gzip 0.3 发布以修复 SSE 压缩问题

Simon Willison··作者 Simon Willison

关键信息

该漏洞影响了内容类型为 `text/event-stream` 的响应,这在 SSE 实现中很常见。修复是在手动运行之前失效的 GitHub Actions 工作流并应用 Starlette 的上游更改后完成的。

资讯摘要

西蒙·威尔逊发布了 asgi-gzip 0.3 版本,以解决 Server-Sent Events (SSE) 响应被错误压缩的问题。这一问题是因为该库原本来自 Starlette,但因一个失效的 GitHub Actions 工作流未能及时同步关键修复。他在部署 Datasette 实例中的新 SSE 功能时发现,datasette-gzip(依赖 asgi-gzip)会错误地压缩 text/event-stream 响应。

在修复工作流并集成 Starlette 的补丁后,两个库现在都能正确处理 SSE 响应。这一事件突显了即使是很小的自动化故障也可能影响依赖第三方工具的生产系统。

资讯正文

<p><strong>发布:</strong> <a href="https://github.com/simonw/asgi-gzip/releases/tag/0.3">asgi-gzip 0.3</a></p>

<p>我在将一个使用 <a href="https://developer.mozilla.org/en-US/docs/Web/API/Server-sent_events">SSE(服务器发送事件)</a> 的新功能部署到生产环境的 Datasette 实例时遇到了问题,发现该实例使用了 <a href="https://github.com/simonw/datasette-gzip">datasette-gzip</a>,而它又依赖于 <a href="https://github.com/simonw/asgi-gzip">asgi-gzip</a>,但后者错误地压缩了 <code>event/text-stream</code> 类型的响应。</p>

<p><code>asgi-gzip</code> 最初是从 Starlette 中提取出来的,并且有一个 <a href="https://simonwillison.net/2022/Apr/28/issue-on-changes/">GitHub Actions 定时工作流</a>,用于检查 Starlette 是否有需要移植到该库的更新……但这个工作流已经停止运行,因此错过了 <a href="https://github.com/Kludex/starlette/commit/a9a8dab0cc3cbd05dca37650fc392717b9fe5bbf">Starlette 自身对这个问题的修复</a>。</p>

<p>我手动运行了该工作流并整合了新的修复,现在 <code>datasette-gzip</code> 和 <code>asgi-gzip</code> 都能正确处理 SSE 响应中的 <code>text/event-stream</code> 类型。</p>

<p>标签: <a href="https://simonwillison.net/tags/gzip">gzip</a>,<a href="https://simonwillison.net/tags/asgi">asgi</a>,<a href="https://simonwillison.net/tags/python">python</a></p>

来源与参考

  1. 原始链接
  2. Release: asgi-gzip 0.3

收录于 2026-04-10