Skip to content

Commit 5b2806a

Browse files
committed
expose response header amount
1 parent a2f15ce commit 5b2806a

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/http/Client.zig

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,9 @@ pub const Transfer = struct {
654654
}
655655

656656
if (buf_len == 2) {
657-
if (getResponseHeader(easy, "content-type", 0)) |value| {
657+
if (getResponseHeader(easy, "content-type", 0)) |ct| {
658658
var hdr = &transfer.response_header.?;
659+
const value = ct.value;
659660
const len = @min(value.len, hdr._content_type.len);
660661
hdr._content_type_len = len;
661662
@memcpy(hdr._content_type[0..len], value[0..len]);
@@ -748,11 +749,19 @@ const HeaderIterator = struct {
748749
}
749750
};
750751

751-
fn getResponseHeader(easy: *c.CURL, name: [:0]const u8, index: usize) ?[]const u8 {
752+
const ResponseHeader = struct {
753+
value: []const u8,
754+
amount: usize,
755+
};
756+
757+
fn getResponseHeader(easy: *c.CURL, name: [:0]const u8, index: usize) ?ResponseHeader {
752758
var hdr: [*c]c.curl_header = null;
753759
const result = c.curl_easy_header(easy, name, index, c.CURLH_HEADER, -1, &hdr);
754760
if (result == c.CURLE_OK) {
755-
return std.mem.span(hdr.*.value);
761+
return .{
762+
.amount = hdr.*.amount,
763+
.value = std.mem.span(hdr.*.value),
764+
};
756765
}
757766

758767
if (result == c.CURLE_FAILED_INIT) {

0 commit comments

Comments
 (0)