mirror of
https://github.com/zigzap/zap.git
synced 2025-10-20 15:14:08 +00:00
Merge pull request #98 from desttinghim/mimetype
Fix docserver, Wrap http_mimetype_register and http_mimetype_clear
This commit is contained in:
commit
0de5c8fbcc
4 changed files with 22 additions and 1 deletions
|
@ -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);
|
||||
|
||||
|
|
18
src/http.zig
18
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();
|
||||
}
|
||||
|
|
|
@ -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".
|
||||
|
|
|
@ -26,6 +26,8 @@ pub fn main() !void {
|
|||
}
|
||||
}
|
||||
|
||||
zap.mimetypeRegister("wasm", "application/wasm");
|
||||
|
||||
var listener = zap.HttpListener.init(.{
|
||||
.port = port,
|
||||
.on_request = on_request,
|
||||
|
|
Loading…
Add table
Reference in a new issue