Something went wrong. Try again.
xburner is an experimental HTTP and gRPC load generator written in Zig.
Something went wrong. Try again.
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152const std = @import("std");
const types = @import("types.zig");
pub const SchemaError = error{ DuplicateRequestId, InvalidHeaderValue, InvalidTemplateVariable,};
pub const TemplateValueKind = enum { path, body, header,};
pub fn validateRequestIds(requests: []const types.HttpRequestTemplate) SchemaError!void { for (requests, 0..) |left, left_index| { for (requests[left_index + 1 ..]) |right| { if (left.id == right.id) return error.DuplicateRequestId; } }}
pub fn validateTemplateValue(value: []const u8, kind: TemplateValueKind) SchemaError!void { if (kind == .header) { if (std.mem.indexOfScalar(u8, value, '\r') != null or std.mem.indexOfScalar(u8, value, '\n') != null) { return error.InvalidHeaderValue; } }
var cursor: usize = 0; while (std.mem.indexOfPos(u8, value, cursor, "${")) |open_index| { const close_index = std.mem.indexOfScalarPos(u8, value, open_index + 2, '}') orelse { return error.InvalidTemplateVariable; }; const key = value[open_index + 2 .. close_index];
if (!(std.mem.startsWith(u8, key, "setup.") or std.mem.startsWith(u8, key, "iter.") or std.mem.startsWith(u8, key, "vu."))) { return error.InvalidTemplateVariable; }
const dot_index = std.mem.indexOfScalar(u8, key, '.') orelse return error.InvalidTemplateVariable; if (dot_index + 1 >= key.len) return error.InvalidTemplateVariable;
cursor = close_index + 1; }}