Pre-size the destination buffer when we know the response content length

This commit is contained in:
Karl Seguin
2025-08-31 20:14:55 +08:00
parent f66f4d9aeb
commit 2a8e51c2d2
3 changed files with 25 additions and 1 deletions

View File

@@ -1040,6 +1040,16 @@ pub const Transfer = struct {
try req.done_callback(req.ctx);
}
pub fn getContentLength(self: *const Transfer) ?u32 {
// It's possible for this to be null even with correct code, due to
// request fulfillment. If transfer.fulfill is called, we won't have
// a handle.
const handle = self._handle orelse return null;
const cl = getResponseHeader(handle.conn.easy, "content-length", 0) orelse return null;
return std.fmt.parseInt(u32, cl.value, 10) catch null;
}
};
pub const ResponseHeader = struct {