From 1aec8031e6296392d819cf37a9a3a50d83de5936 Mon Sep 17 00:00:00 2001 From: jaina heartles Date: Sat, 8 Oct 2022 00:51:57 -0700 Subject: [PATCH] Preliminary support for query parameters --- src/http/routing.zig | 3 ++- src/util/Url.zig | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/http/routing.zig b/src/http/routing.zig index a22b6c7..472d5aa 100644 --- a/src/http/routing.zig +++ b/src/http/routing.zig @@ -85,8 +85,9 @@ pub fn Router(comptime ServerContext: type, comptime RequestContext: type) type }; pub fn dispatch(self: Self, sctx: ServerContext, rctx: RequestContext, method: std.http.Method, path: []const u8) anyerror!void { + const eff_path = std.mem.sliceTo(std.mem.sliceTo(path, '#'), '?'); for (self.routes) |r| { - r.dispatch(sctx, rctx, method, path) catch |err| switch (err) { + r.dispatch(sctx, rctx, method, eff_path) catch |err| switch (err) { error.RouteNotApplicable => continue, else => return err, }; diff --git a/src/util/Url.zig b/src/util/Url.zig index 515e507..35d74e8 100644 --- a/src/util/Url.zig +++ b/src/util/Url.zig @@ -43,6 +43,7 @@ pub fn parse(url: []const u8) !Url { pub fn getQuery(self: Url, param: []const u8) ?[]const u8 { var key_start: usize = 0; + std.log.debug("query: {s}", .{self.query}); while (key_start < self.query.len) { const key_end = for (self.query[key_start..]) |ch, i| { if (ch == '=') break key_start + i;