From 49d629ba55ce680c6865b2200ab3ce66ac991c11 Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Tue, 23 Apr 2024 15:15:40 -0600 Subject: [PATCH 1/3] fix: last_modifed -> last_modified --- src/request.zig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/request.zig b/src/request.zig index 1345379..24a02f5 100644 --- a/src/request.zig +++ b/src/request.zig @@ -470,7 +470,7 @@ pub const HttpHeaderCommon = enum(usize) { /// Represents the HTTP Header "Host". host, /// Represents the HTTP Header "Last-Modified". - last_modifed, + last_modified, /// Represents the HTTP Header "Origin". origin, /// Represents the HTTP Header "Set-Cookie". From 3e4c29409ef73a45a78289028f057c37dde51a52 Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Tue, 23 Apr 2024 16:13:07 -0600 Subject: [PATCH 2/3] fix: docserver: server wasm with correct mimetype --- build.zig | 1 + tools/docserver.zig | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/build.zig b/build.zig index a8d2f4b..a2a6def 100644 --- a/build.zig +++ b/build.zig @@ -247,6 +247,7 @@ pub fn build(b: *std.Build) !void { const docserver_run_step = b.step("run-docserver", "run the docserver"); const docserver_run = b.addRunArtifact(docserver_exe); + docserver_run.addPrefixedDirectoryArg("--docs=", docs_obj.getEmittedBinDirectory()); docserver_run_step.dependOn(&docserver_run.step); docserver_run_step.dependOn(docserver_step); diff --git a/tools/docserver.zig b/tools/docserver.zig index 85b5167..8e7cca7 100644 --- a/tools/docserver.zig +++ b/tools/docserver.zig @@ -26,6 +26,15 @@ pub fn main() !void { } } + const ext = "wasm"; + var buf: [0xF]u8 = undefined; + @memcpy(buf[0..ext.len], ext); + + const mimetype = "application/wasm"; + const fio_mimetype = zap.fio.fiobj_str_new(mimetype[0..], mimetype.len); + + zap.fio.http_mimetype_register(buf[0..ext.len], ext.len, fio_mimetype); + var listener = zap.HttpListener.init(.{ .port = port, .on_request = on_request, From a907ef9fadf1d3eae5a0166233a5b03eee59e4bf Mon Sep 17 00:00:00 2001 From: Louis Pearson Date: Tue, 23 Apr 2024 16:44:18 -0600 Subject: [PATCH 3/3] feat: Wrap mimetypeRegister and mimetypeClear --- src/http.zig | 18 ++++++++++++++++++ tools/docserver.zig | 9 +-------- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/http.zig b/src/http.zig index 5241c3f..6a93e11 100644 --- a/src/http.zig +++ b/src/http.zig @@ -1,4 +1,5 @@ const std = @import("std"); +const fio = @import("fio.zig"); /// HTTP Status codes according to `rfc7231` /// https://tools.ietf.org/html/rfc7231#section-6 @@ -126,3 +127,20 @@ pub fn methodToEnum(method: ?[]const u8) Method { return Method.UNKNOWN; } } + +/// Registers a new mimetype to be used for files ending with the given extension. +pub fn mimetypeRegister(file_extension: []const u8, mime_type_str: []const u8) void { + // NOTE: facil.io is expecting a non-const pointer to u8 values, but it does not + // not appear to actually modify the value. Here we do a const cast so + // that it is easy to pass static strings to http_mimetype_register without + // needing to allocate a buffer on the heap. + const extension = @constCast(file_extension); + const mimetype = fio.fiobj_str_new(mime_type_str.ptr, mime_type_str.len); + + fio.http_mimetype_register(extension.ptr, extension.len, mimetype); +} + +/// Clears the Mime-Type registry (it will be empty after this call). +pub fn mimetypeClear() void { + fio.http_mimetype_clear(); +} diff --git a/tools/docserver.zig b/tools/docserver.zig index 8e7cca7..e5a918e 100644 --- a/tools/docserver.zig +++ b/tools/docserver.zig @@ -26,14 +26,7 @@ pub fn main() !void { } } - const ext = "wasm"; - var buf: [0xF]u8 = undefined; - @memcpy(buf[0..ext.len], ext); - - const mimetype = "application/wasm"; - const fio_mimetype = zap.fio.fiobj_str_new(mimetype[0..], mimetype.len); - - zap.fio.http_mimetype_register(buf[0..ext.len], ext.len, fio_mimetype); + zap.mimetypeRegister("wasm", "application/wasm"); var listener = zap.HttpListener.init(.{ .port = port,