From 554c42ede7d5e280a244bd2fb460db085c702ca7 Mon Sep 17 00:00:00 2001 From: floscodes Date: Wed, 17 May 2023 23:33:23 +0200 Subject: [PATCH] add Request methods --- src/types.zig | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/src/types.zig b/src/types.zig index a1b1edd..a806b78 100644 --- a/src/types.zig +++ b/src/types.zig @@ -97,8 +97,24 @@ pub const Request = struct { uri: []const u8, /// Represents the request body sent by the client body: []const u8, - /// Represents the sent cookies + /// Represents a Request Cookie pub const Cookie = reqcookie.Cookie; + + /// Get Request Cookie value by Cookie name + pub fn cookie(self: *Request, name: []const u8) ?[]const u8 { + for (self.*.cookies) |c| { + if (eql(u8, name, c.name)) return c.value; + } + return null; + } + + /// Get Header value by Header key + pub fn header(self: *Request, key: []const u8) ?[]const u8 { + for (self.*.headers) |h| { + if (eql(u8, key, h.key)) return h.value; + } + return null; + } }; /// Represents a standard http-Response sent by the webapp (server).