aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-25 19:23:18 -0700
committerGravatar Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2022-08-25 19:23:18 -0700
commit49bec758b7441662e4a3e8757a58a4403d6a308b (patch)
tree1b2a4de985b0907e089b0b497dab0b6642a13fe7
parent950d03a9ea8aed3eccca7e2cee3a9d0b0a0e3436 (diff)
downloadbun-49bec758b7441662e4a3e8757a58a4403d6a308b.tar.gz
bun-49bec758b7441662e4a3e8757a58a4403d6a308b.tar.zst
bun-49bec758b7441662e4a3e8757a58a4403d6a308b.zip
Faster way to lookup mimetype
-rw-r--r--src/bun.js/webcore/response.zig15
1 files changed, 8 insertions, 7 deletions
diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig
index 2e6b73be1..fc79bf377 100644
--- a/src/bun.js/webcore/response.zig
+++ b/src/bun.js/webcore/response.zig
@@ -64,11 +64,14 @@ pub const Response = struct {
}
pub fn redirectLocation(this: *const Response) ?[]const u8 {
- return this.header("location");
+ return this.header(.Location);
}
- pub fn header(this: *const Response, comptime name: []const u8) ?[]const u8 {
- return (this.body.init.headers orelse return null).get(name);
+ pub fn header(this: *const Response, name: JSC.FetchHeaders.HTTPHeaderName) ?[]const u8 {
+ return if ((this.body.init.headers orelse return null).fastGet(name)) |str|
+ str.slice()
+ else
+ null;
}
pub const Props = struct {};
@@ -244,7 +247,7 @@ pub const Response = struct {
}
pub fn mimeTypeWithDefault(response: *const Response, default: MimeType, request_ctx_: ?*const RequestContext) string {
- if (response.header("content-type")) |content_type| {
+ if (response.header(.ContentType)) |content_type| {
// Remember, we always lowercase it
// hopefully doesn't matter here tho
return content_type;
@@ -4118,10 +4121,8 @@ pub const Request = struct {
pub fn mimeType(this: *const Request) string {
if (this.headers) |headers| {
- // Remember, we always lowercase it
- // hopefully doesn't matter here tho
if (headers.fastGet(.ContentType)) |content_type| {
- return content_type;
+ return content_type.slice();
}
}