From bddd721954c736f189935e6840878530f600dc2a Mon Sep 17 00:00:00 2001 From: zzstoatzz Date: Thu, 30 Jul 2026 14:57:02 -0500 Subject: [PATCH] Stream lazily buffered request bodies --- src/http/api.zig | 6 +++++- tools/smoke.sh | 4 ++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/http/api.zig b/src/http/api.zig index ad71b7e..7d7b00c 100644 --- a/src/http/api.zig +++ b/src/http/api.zig @@ -215,8 +215,12 @@ pub fn readBody(request: *Request, buf: []u8) ![]const u8 { } pub fn readBodyAlloc(request: *Request, allocator: std.mem.Allocator, max_len: usize) ![]const u8 { + if (request.body_len > max_len) return error.BodyTooLarge; + if (request.unread_body > 0) { + var body_reader = try request.reader(30_000); + return try body_reader.interface.readAlloc(allocator, request.body_len); + } const body = request.body() orelse ""; - if (body.len > max_len) return error.BodyTooLarge; return try allocator.dupe(u8, body); } diff --git a/tools/smoke.sh b/tools/smoke.sh index 8ef7e40..d4693e8 100755 --- a/tools/smoke.sh +++ b/tools/smoke.sh @@ -179,13 +179,13 @@ blob_head=$(curl -sSI -o /dev/null -w '%{http_code}' "$base/xrpc/com.atproto.syn test "$blob_head" = "200" large_blob_payload="${TMPDIR:-/tmp}/zds-smoke-large-blob.jpg" -dd if=/dev/zero bs=1024 count=600 of="$large_blob_payload" 2>/dev/null +dd if=/dev/zero bs=1048576 count=17 of="$large_blob_payload" 2>/dev/null large_blob=$(curl -fsS -X POST "$base/xrpc/com.atproto.repo.uploadBlob" \ -H "authorization: Bearer $token" \ -H 'content-type: image/jpeg' \ --data-binary "@$large_blob_payload") printf '%s' "$large_blob" | grep -q '"blob":' -printf '%s' "$large_blob" | grep -q '"size":614400' +printf '%s' "$large_blob" | grep -q '"size":17825792' oauth_info=$(curl -fsS -H 'accept: application/json' "$base/oauth/authorize?request_uri=urn%3Aietf%3Aparams%3Aoauth%3Arequest_uri%3Asmoke-oauth") printf '%s' "$oauth_info" | grep -q '"login_hint":"smoke.test"' -- 2.51.2