const std = @import("std"); const zap = @import("zap"); const mem = std.mem; fn sendJson(r: zap.Request, body: []const u8) void { r.setHeader("content-type", "application/json") catch {}; r.setHeader("access-control-allow-origin", "*") catch {}; r.setHeader("access-control-allow-methods", "GET, POST, PATCH, DELETE, OPTIONS") catch {}; r.setHeader("access-control-allow-headers", "content-type, x-prefect-api-version") catch {}; r.sendBody(body) catch {}; } pub fn health(r: zap.Request) !void { // match python prefect server response r.setHeader("content-type", "text/plain") catch {}; r.setHeader("access-control-allow-origin", "*") catch {}; r.sendBody("ok") catch {}; } pub fn csrfToken(r: zap.Request) !void { // prefect client expects a csrf token with client id and expiration // extract client from query string: /api/csrf-token?client=... const target = r.path orelse "/"; var client_id: []const u8 = "unknown"; if (mem.indexOf(u8, target, "client=")) |start| { const rest = target[start + 7 ..]; if (mem.indexOf(u8, rest, "&")) |end| { client_id = rest[0..end]; } else { client_id = rest; } } var buf: [512]u8 = undefined; const response = std.fmt.bufPrint(&buf, \\{{"token":"zig-csrf-token","client":"{s}","expiration":"2099-01-01T00:00:00Z"}} , .{client_id}) catch { sendJson(r, "{\"token\":\"zig-csrf-token\",\"client\":\"unknown\",\"expiration\":\"2099-01-01T00:00:00Z\"}"); return; }; sendJson(r, response); } pub fn version(r: zap.Request) !void { // return version as JSON string (FastAPI behavior) // must return 3.x to match Python client major version sendJson(r, "\"3.0.0\""); }