Skip to content

Commit 9e88adb

Browse files
Merge pull request #557 from lightpanda-io/fix_peek
peek must check existing data first
2 parents 4a696b4 + 837188f commit 9e88adb

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/http/client.zig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,6 +1576,19 @@ pub const Response = struct {
15761576
}
15771577

15781578
pub fn peek(self: *Response) ![]u8 {
1579+
if (try self.processData()) |data| {
1580+
// We already have some or all of the body. This happens because
1581+
// we always read as much as we can, so getting the header and
1582+
// part/all of the body is normal.
1583+
if (data.len > 100) {
1584+
self._peek_buf = data;
1585+
self._peek_len = data.len;
1586+
return data;
1587+
}
1588+
@memcpy(self._peek_buf[0..data.len], data);
1589+
self._peek_len = data.len;
1590+
}
1591+
15791592
while (true) {
15801593
var peek_buf = self._peek_buf;
15811594
const peek_len = self._peek_len;

0 commit comments

Comments
 (0)