aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/http/mime_type.zig41
1 files changed, 37 insertions, 4 deletions
diff --git a/src/http/mime_type.zig b/src/http/mime_type.zig
index 5818c88ea..8e970f46d 100644
--- a/src/http/mime_type.zig
+++ b/src/http/mime_type.zig
@@ -62,6 +62,13 @@ pub const Category = enum {
else => false,
};
}
+
+ pub fn autosetFilename(this: Category) bool {
+ return switch (this) {
+ .wasm, .font, .image, .audio, .video, .javascript, .html, .text, .css, .json => false,
+ else => true,
+ };
+ }
};
pub const other = MimeType.initComptime("application/octet-stream", .other);
@@ -106,11 +113,21 @@ pub fn init(str_: string) MimeType {
return json;
}
}
+
+ if (strings.eqlComptimeIgnoreLen(str, "octet-stream")) {
+ return other;
+ }
+
+ if (strings.eqlComptime(str, "wasm")) {
+ return wasm;
+ }
+
+ return MimeType{ .value = str_, .category = .application };
},
"font".len => {
if (strings.eqlComptimeIgnoreLen(category_, "font")) {
return MimeType{
- .value = str,
+ .value = str_,
.category = .font,
};
}
@@ -129,23 +146,39 @@ pub fn init(str_: string) MimeType {
}
if (strings.eqlComptime(str, "plain")) {
- return MimeType{ .value = "text/plain", .category = .text };
+ return all.@"text/plain";
}
+
+ return MimeType{ .value = str_, .category = .text };
}
},
"image".len => {
if (strings.eqlComptimeIgnoreLen(category_, "image")) {
return MimeType{
- .value = str,
+ .value = str_,
.category = .image,
};
}
+
+ if (strings.eqlComptimeIgnoreLen(category_, "audio")) {
+ return MimeType{
+ .value = str_,
+ .category = .audio,
+ };
+ }
+
+ if (strings.eqlComptimeIgnoreLen(category_, "video")) {
+ return MimeType{
+ .value = str_,
+ .category = .video,
+ };
+ }
},
else => {},
}
}
- return MimeType{ .value = str, .category = .other };
+ return MimeType{ .value = str_, .category = .other };
}
// TODO: improve this