diff options
author | 2022-08-25 19:23:18 -0700 | |
---|---|---|
committer | 2022-08-25 19:23:18 -0700 | |
commit | 49bec758b7441662e4a3e8757a58a4403d6a308b (patch) | |
tree | 1b2a4de985b0907e089b0b497dab0b6642a13fe7 /src | |
parent | 950d03a9ea8aed3eccca7e2cee3a9d0b0a0e3436 (diff) | |
download | bun-49bec758b7441662e4a3e8757a58a4403d6a308b.tar.gz bun-49bec758b7441662e4a3e8757a58a4403d6a308b.tar.zst bun-49bec758b7441662e4a3e8757a58a4403d6a308b.zip |
Faster way to lookup mimetype
Diffstat (limited to 'src')
-rw-r--r-- | src/bun.js/webcore/response.zig | 15 |
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(); } } |