使用ASP.NET核心响应时压缩。

发布于 2025-01-23 04:42:38 字数 403 浏览 3 评论 0原文

当使用响应。BodyWriter从ASP.NET Core Web API端点输出JSON属性时,似乎忽略了配置的压缩方法。

使用推荐的services.AddresponSecompressionapp.useresseponsecompression在startup.cs中启用压缩。适当的中间件。

但是,使用pipewriter写入输出的方法似乎完全忽略了这些设置。

当然,我们可以直接将压缩数据写入响应。所有这些已经由ASP.NET在某个地方完成,因此理想情况下,我想避免自己重新实现所有这些。

是否有标准方法将正确的压缩应用于Bobswriter管道?

When using the Response.BodyWriter property to output JSON from a ASP.NET Core Web API endpoint, it seems the configured compression method is ignored.

Compression is enabled using the recommended services.AddResponseCompression and app.UseResponseCompression calls in Startup.cs, and indeed this works for normal endpoints that return object instances that are later serialized by the appropriate middleware.

However, using the PipeWriter method to write output seems to ignore these settings completely.

Of course, we can write compressed data to the Response.BodyWriter pipe directly, but this appears to involve determining the best compression method to use, setting up a Brotli or Gzip writer, and sending chunks through that - all of this is already done by ASP.NET somewhere, so ideally I'd like to avoid re-implementing all this myself.

Is there a standard way to apply the correct compression to the BodyWriter pipe?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文