Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix docserver, Wrap http_mimetype_register and http_mimetype_clear #98

Merged
merged 3 commits into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
18 changes: 18 additions & 0 deletions src/http.zig
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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();
}
2 changes: 1 addition & 1 deletion src/request.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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".
Expand Down
2 changes: 2 additions & 0 deletions tools/docserver.zig
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ pub fn main() !void {
}
}

zap.mimetypeRegister("wasm", "application/wasm");

var listener = zap.HttpListener.init(.{
.port = port,
.on_request = on_request,
Expand Down
Loading