Skip to content

feat(web): streaming response API for the HTTP client #51

Closed

Description

@Antruly

背景

uvcpp_http_client 只在完整响应收完后回调(src/web/uvcpp_http_client.h:9 的说明),没有 body 分片接口。uvscope 0.4 计划支持大响应流式查看/下载,反向代理也希望减少整包缓冲。

服务端已经有成熟的流式能力(begin_chunked / write_chunk / stream_route),客户端缺对应的一半。

建议

  1. 增加流式发送接口,例如:
    int send_stream(const uvcpp_http_request& req,
                    std::function<void(const uvcpp_http_response& head)> on_headers,
                    std::function<bool(const char* data, size_t len)> on_body,
                    std::function<void(int status)> on_end);
    on_body 返回 false 表示暂停/中止,并配套 resume()。
  2. 保留现有 send() / send_wait() 行为不变。
  3. HTTP/1.1 必须先落地;h2/h3 可以在同一接口下逐步接入。
  4. 明确背压语义:回调处理不过来时是暂停 socket 读,而不是无限堆内存。

验收

  • 100 MiB 响应在常量内存下接收并落盘;
  • 中途取消能及时关闭连接;
  • 小响应与现有完整响应 API 结果一致。

建议进入 1.9;如果 1.8.2 范围允许,先做 h1 也可。

Activity

  1. Antruly commented on Oct 20, 2026

    @Antruly
    OwnerAuthor

    已实现并合入 master(91b163d):uvcpp_http_client::send_stream()(h1)+ resume() / cancel_stream();on_body 返回 false 会停读 socket。用例 web_http_client_stream_func(小响应一致、4 MiB 背压、2 MiB chunked、取消)。

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