atproto relay implementation in zig zlay.waow.tech
9
fork

Configure Feed

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

fix: httpRespond buffer overflow for large responses

Write headers and body as separate writes instead of formatting
everything into a single 4KB buffer. Fixes 502 errors when
listReposByCollection returns >90 results.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

zzstoatzz a477421e 65da8b09

+5 -4
+5 -4
src/main.zig
··· 803 803 } 804 804 805 805 fn httpRespond(stream: std.net.Stream, status: []const u8, content_type: []const u8, body: []const u8) void { 806 - var buf: [4096]u8 = undefined; 807 - // include Server header for relay loop detection (Go relay: "indigo-relay (atproto-relay)") 808 - const response = std.fmt.bufPrint(&buf, "HTTP/1.1 {s}\r\nContent-Type: {s}\r\nContent-Length: {d}\r\nServer: zlay (atproto-relay)\r\nConnection: close\r\n\r\n{s}", .{ status, content_type, body.len, body }) catch return; 809 - _ = stream.write(response) catch {}; 806 + // write headers first, then body separately (body can be much larger than header buffer) 807 + var hdr_buf: [512]u8 = undefined; 808 + const hdr = std.fmt.bufPrint(&hdr_buf, "HTTP/1.1 {s}\r\nContent-Type: {s}\r\nContent-Length: {d}\r\nServer: zlay (atproto-relay)\r\nConnection: close\r\n\r\n", .{ status, content_type, body.len }) catch return; 809 + _ = stream.write(hdr) catch return; 810 + _ = stream.write(body) catch {}; 810 811 } 811 812 812 813 fn parseEnvInt(comptime T: type, key: []const u8, default: T) T {