From 0b368f14dd6497d6d2c92f866c8a3ab85573544d Mon Sep 17 00:00:00 2001 From: Rene Schallner Date: Sun, 29 Jan 2023 16:27:06 +0100 Subject: [PATCH] Added setContentTypeFromPath() --- examples/hello2/hello2.zig | 1 + src/zap.zig | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/examples/hello2/hello2.zig b/examples/hello2/hello2.zig index b4e674f..372046d 100644 --- a/examples/hello2/hello2.zig +++ b/examples/hello2/hello2.zig @@ -13,6 +13,7 @@ fn on_request(r: zap.SimpleRequest) void { std.debug.print(">> BODY: {s}\n", .{the_body}); } + r.setContentTypeFromPath(); _ = r.sendBody( \\ \\

Hello from ZAP!!!

diff --git a/src/zap.zig b/src/zap.zig index 5c0ab95..1d6f81b 100644 --- a/src/zap.zig +++ b/src/zap.zig @@ -83,6 +83,14 @@ pub const SimpleRequest = struct { }); } + pub fn setContentTypeFromPath(self: *const Self) void { + _ = C.fiobj_hash_set( + self.h.*.private_data.out_headers, + C.HTTP_HEADER_CONTENT_TYPE, + C.http_mimetype_find2(self.h.*.path), + ); + } + pub fn setHeader(self: *const Self, name: []const u8, value: []const u8) void { const hname: C.fio_str_info_s = .{ .data = toCharPtr(name),