Skip to content

feat(web): decode br and make the client decompression threshold configurable #47

Closed

Description

@Antruly

背景

uvscope 0.4 的响应解码计划支持 gzip / br 与“原始字节”切换。服务端已经有 brotli 压缩(UVCPP_BROTLI_ENABLE),但 HTTP 客户端没有:

  • src/web/uvcpp_http_client.cpp 的 add_accept_encoding() 固定写 gzip, deflate(约 800 行);
  • decompress_response_body() 只认 gzip / deflate,br 被原样保留(约 820 行);
  • 解压门槛 1024 字节写死,且没有配置接口(src/web/uvcpp_http_client.h:258 的注释已说明)。

建议

  1. UVCPP_BROTLI_ENABLE 打开时,客户端 Accept-Encoding 加入 br,并在 decompress_response_body() 里用 BrotliDecoder 解码。
  2. 调用方自己设置过 Accept-Encoding 时保持不覆盖。
  3. 增加解压门槛配置,例如 set_compression_min_body_size(size_t)(0 = 总是解压);默认值可保持 1024 以兼容。
  4. 可选:返回是否实际解压过(例如 uvcpp_http_response::body_decompressed),便于调试器区分“原始压缩字节”和“已解码字节”。

验收

  • 本地返回 content-encoding: br 的服务端,响应体被正确解码;
  • gzip / deflate 不回归;
  • 小于门槛的 body 在门槛设为 0 时也会解码;
  • 未编入 brotli 的构建仍只发 gzip / deflate,不出现“协商了 br 却解不开”。

建议进入 1.8.2。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions