diff --git a/src/main.zig b/src/main.zig index bbccf09..36e3672 100644 --- a/src/main.zig +++ b/src/main.zig @@ -803,10 +803,11 @@ fn findHeader(headers: []const u8, name: []const u8) ?[]const u8 { } fn httpRespond(stream: std.net.Stream, status: []const u8, content_type: []const u8, body: []const u8) void { - var buf: [4096]u8 = undefined; - // include Server header for relay loop detection (Go relay: "indigo-relay (atproto-relay)") - 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; - _ = stream.write(response) catch {}; + // write headers first, then body separately (body can be much larger than header buffer) + var hdr_buf: [512]u8 = undefined; + 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; + _ = stream.write(hdr) catch return; + _ = stream.write(body) catch {}; } fn parseEnvInt(comptime T: type, key: []const u8, default: T) T {