Implement Network.getResponseBody

Add response_data event, CDP now captures the full body so that it can respond
to the Network.getResponseBody. This isn't memory efficient, but I don't see
another way to do it. At least this way, it's only capturing/storing every
response body when (a) CDP is used and (b) Network.enabled is called. That is,
as opposed to baking this into Http/Client.zig, which would force the memory
consumption for all use-cases.

There's arguably some optimizations we could make for XHR requests, which also
dupe/own the response. As of now, the response is dupe'd separately for CDP
and XHR.
This commit is contained in:
Karl Seguin
2025-08-21 10:32:03 +08:00
parent 557f8444b2
commit cd33e9ad0e
4 changed files with 84 additions and 45 deletions

View File

@@ -757,7 +757,7 @@ pub const Transfer = struct {
};
if (transfer.client.notification) |notification| {
notification.dispatch(.http_headers_done, &.{
notification.dispatch(.http_response_header_done, &.{
.transfer = transfer,
});
}
@@ -780,10 +780,19 @@ pub const Transfer = struct {
}
transfer.bytes_received += chunk_len;
transfer.req.data_callback(transfer, buffer[0..chunk_len]) catch |err| {
const chunk = buffer[0..chunk_len];
transfer.req.data_callback(transfer, chunk) catch |err| {
log.err(.http, "data_callback", .{ .err = err, .req = transfer });
return c.CURL_WRITEFUNC_ERROR;
};
if (transfer.client.notification) |notification| {
notification.dispatch(.http_response_data, &.{
.data = chunk,
.transfer = transfer,
});
}
return chunk_len;
}