// Minimal HTTP server benchmark - Zig version (single-threaded)
// Compile: zig build-exe -O ReleaseFast http_server.zig
// Test: wrk -t2 -c50 -d5s http://localhost:8082/

const std = @import("std");
const net = std.net;

const response = "HTTP/1.1 200 OK\r\nContent-Type: application/json\r\nContent-Length: 15\r\n\r\n{\"status\":\"ok\"}";

pub fn main() !void {
    const address = net.Address.initIp4(.{ 0, 0, 0, 0 }, 8082);
    var server = try address.listen(.{ .reuse_address = true });
    defer server.deinit();

    std.debug.print("Zig HTTP server listening on port 8082\n", .{});

    while (true) {
        var connection = server.accept() catch continue;
        defer connection.stream.close();

        var buf: [1024]u8 = undefined;
        _ = connection.stream.read(&buf) catch continue;
        _ = connection.stream.write(response) catch continue;
    }
}
