atproto pds in zig pds.zat.dev
pds atproto
24

Configure Feed

Select the types of activity you want to include in your feed.

Read HTTP bodies through bounded chunks

zzstoatzz (May 22, 2026, 3:56 PM -0500) 31476fc6 a42c349c

+8 -2
+8 -2
src/http/api.zig
··· 57 57 if (len > buf.len) return error.BodyTooLarge; 58 58 var total: usize = 0; 59 59 const expected: usize = @intCast(len); 60 + var chunk: [8192]u8 = undefined; 60 61 while (total < expected) { 61 - const n = try reader.readSliceShort(buf[total..expected]); 62 + const remaining = expected - total; 63 + const n = try reader.readSliceShort(chunk[0..@min(chunk.len, remaining)]); 62 64 if (n == 0) return error.UnexpectedEof; 65 + @memcpy(buf[total..][0..n], chunk[0..n]); 63 66 total += n; 64 67 } 65 68 return buf[0..expected]; ··· 87 90 if (len > max_len) return error.BodyTooLarge; 88 91 const body = try allocator.alloc(u8, @intCast(len)); 89 92 var total: usize = 0; 93 + var chunk: [8192]u8 = undefined; 90 94 while (total < body.len) { 91 - const n = try reader.readSliceShort(body[total..]); 95 + const remaining = body.len - total; 96 + const n = try reader.readSliceShort(chunk[0..@min(chunk.len, remaining)]); 92 97 if (n == 0) return error.UnexpectedEof; 98 + @memcpy(body[total..][0..n], chunk[0..n]); 93 99 total += n; 94 100 } 95 101 return body;