1
0
Fork 0
mirror of https://github.com/zigzap/zap.git synced 2025-10-20 23:24:09 +00:00

fix: move getHeaderCommon to zap.zig

This commit is contained in:
Louis Pearson 2024-04-24 17:29:34 -06:00
parent d83bf5afa7
commit 583ad97633
2 changed files with 17 additions and 18 deletions

View file

@ -1,5 +1,4 @@
const std = @import("std"); const std = @import("std");
const fio = @import("fio.zig");
/// HTTP Status codes according to `rfc9110` /// HTTP Status codes according to `rfc9110`
/// https://datatracker.ietf.org/doc/html/rfc9110#name-status-codes /// https://datatracker.ietf.org/doc/html/rfc9110#name-status-codes
@ -149,20 +148,3 @@ pub fn methodToEnum(method: ?[]const u8) Method {
return Method.UNKNOWN; 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();
}

View file

@ -122,6 +122,23 @@ pub fn startWithLogging(args: fio.fio_start_args) void {
fio.fio_start(args); fio.fio_start(args);
} }
/// 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();
}
pub const ListenError = error{ pub const ListenError = error{
AlreadyListening, AlreadyListening,
ListenError, ListenError,